Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


XML Parsing :: Not Allow Special Charachters.


XML Parsing :: Not Allow Special Charachters.

Author
Message
Jayraj.Todkar
Jayraj.Todkar
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 50
Hi ,

I am facing one problem with xml parsing.

When I pass the special characters in XML string following error occurs.

The XML parse error 0xc00ce504 occurred on line number 1, near the XML text "".

Here is the code.

DECLARE @XmlString VARCHAR(MAX)
DECLARE @id INT

SET @XmlString = N''

exec sp_xml_preparedocument @id output, @XmlString

(select contactid,firstname,lastname,Email,Status from OpenXML(@id, '/users/contacts')
with(contactid INT '@contactid',firstname varchar(25) '@firstname',lastname varchar(25) '@lastname',email varchar(255) '@email',Status varchar(5) '@status')
)


Please suggest me solution.

Thanks,
Jayraj Todkar
LutzM
LutzM
SSCertifiable
SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)

Group: General Forum Members
Points: 7001 Visits: 13559
The problem is the content of firstname and lastname: The character "&" causes the problem.

lastname="sddgdf@#$%^" will work
lastname="sddgdf@#$%^&" won't work.



Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Jayraj.Todkar
Jayraj.Todkar
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 50
Hi,

Is there any solution to overcome this situation?

Best Regards,
Jayraj Todkar
Jayraj.Todkar
Jayraj.Todkar
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 50
Hi,

Is there any solution to overcome this situation?

Best Regards,
Jayraj Todkar
Jayraj.Todkar
Jayraj.Todkar
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 50
Hi,

Is there any solution to overcome this situation?

Best Regards,
Jayraj Todkar
Adam Gojdas
Adam Gojdas
SSC Journeyman
SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)

Group: General Forum Members
Points: 96 Visits: 1429
Jayraj.Todkar (9/16/2009)
Hi,

Is there any solution to overcome this situation?

Best Regards,
Jayraj Todkar


I am not entirely sure of the problem but you may try to entity encode the variables that you will be using to handle the special characters. An example of doing this is the following. You will see in the select that special characters are encoded:


DECLARE @lastName nvarchar(MAX)
DECLARE @encodeLastName nvarchar(MAX)

SET @lastName = N'sddgdf@#$%^&<> '

SET @encodeLastName = CONVERT(nvarchar(max), (SELECT @lastname FOR XML PATH('')) )

SELECT @encodeLastName [@encodeLastName]



Run the example to see that the output has special characters entity encoded.
Jayraj.Todkar
Jayraj.Todkar
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 50
Thank You,

It’s really helpful solution.

Jayraj
Jayraj.Todkar
Jayraj.Todkar
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 50
Thank You,

It’s really helpful solution.

Jayraj
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search