XML Parsing :: Not Allow Special Charachters.

  • 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

  • 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[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Hi,

    Is there any solution to overcome this situation?

    Best Regards,

    Jayraj Todkar

  • Hi,

    Is there any solution to overcome this situation?

    Best Regards,

    Jayraj Todkar

  • Hi,

    Is there any solution to overcome this situation?

    Best Regards,

    Jayraj Todkar

  • 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.

  • Thank You,

    It’s really helpful solution.

    Jayraj

  • Thank You,

    It’s really helpful solution.

    Jayraj

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply