Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

XML Parsing :: Not Allow Special Charachters. Expand / Collapse
Author
Message
Posted Wednesday, September 16, 2009 5:14 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Sunday, August 22, 2010 10:09 PM
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





Post #788836
Posted Wednesday, September 16, 2009 9:22 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:52 AM
Points: 6,932, Visits: 12,663
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
Post #789052
Posted Wednesday, September 16, 2009 11:18 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Sunday, August 22, 2010 10:09 PM
Points: 29, Visits: 50
Hi,

Is there any solution to overcome this situation?

Best Regards,
Jayraj Todkar
Post #789396
Posted Wednesday, September 16, 2009 11:21 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Sunday, August 22, 2010 10:09 PM
Points: 29, Visits: 50
Hi,

Is there any solution to overcome this situation?

Best Regards,
Jayraj Todkar
Post #789398
Posted Wednesday, September 16, 2009 11:23 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Sunday, August 22, 2010 10:09 PM
Points: 29, Visits: 50
Hi,

Is there any solution to overcome this situation?

Best Regards,
Jayraj Todkar
Post #789399
Posted Monday, September 21, 2009 9:42 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, November 01, 2013 8:49 AM
Points: 79, Visits: 1,328
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.
Post #791251
Posted Monday, September 21, 2009 11:19 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Sunday, August 22, 2010 10:09 PM
Points: 29, Visits: 50
Thank You,

It’s really helpful solution.

Jayraj
Post #791508
Posted Monday, September 21, 2009 11:22 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Sunday, August 22, 2010 10:09 PM
Points: 29, Visits: 50
Thank You,

It’s really helpful solution.

Jayraj
Post #791509
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse