September 16, 2009 at 5:14 am
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
September 16, 2009 at 9:22 am
The problem is the content of firstname and lastname: The character "&" causes the problem.
lastname="sddgdf@#$%^" will work
lastname="sddgdf@#$%^&" won't work.
September 16, 2009 at 11:18 pm
Hi,
Is there any solution to overcome this situation?
Best Regards,
Jayraj Todkar
September 16, 2009 at 11:21 pm
Hi,
Is there any solution to overcome this situation?
Best Regards,
Jayraj Todkar
September 16, 2009 at 11:23 pm
Hi,
Is there any solution to overcome this situation?
Best Regards,
Jayraj Todkar
September 21, 2009 at 9:42 am
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.
September 21, 2009 at 11:19 pm
Thank You,
It’s really helpful solution.
Jayraj
September 21, 2009 at 11:22 pm
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