Forum Discussion
Doug_Marquardt
Jul 30, 2022Copper Contributor
XML Conversion For Node Text Containing &
When I cast a string (which is xml) to the xml data type and the node comments contain & it gets converted to &. For example: Declare @xml xml =
'
<SHOP_INSTRUCTIONS>
Remove & return to s...
- Aug 02, 2022See the Wikipedia link I posted, one way is &
olafhelper
Aug 01, 2022Bronze Contributor
Doug_Marquardt , & is just a different (decimal) encoding of & = ampersand.
See List of XML and HTML character entity references - Wikipedia
- Doug_MarquardtAug 01, 2022Copper Contributor
Yes, I realize that... but if I do this it throws an error:
Declare @xml xml = ' <SHOP_INSTRUCTIONS> Remove & return to stock. </SHOP_INSTRUCTIONS> '; Select @xml; XML parsing: line 3, character 9, illegal name characterSo how do I represent & as part of the node text?
- olafhelperAug 02, 2022Bronze ContributorSee the Wikipedia link I posted, one way is &
- Doug_MarquardtAug 03, 2022Copper ContributorI finally figured out what my issue was... I didn't understand that the $amp; would be converted to & when reading the node text value with the XML parser. I was viewing the XML in SQL Server results grid.
I'm new to XML in SQL Server so this is new to me.
Thanks.