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 stock.
</SHOP_INSTRUCTIONS>
';
Select @xml;
/*
Return This:
<SHOP_INSTRUCTIONS>
Remove & return to stock.
</SHOP_INSTRUCTIONS>
*/
I would expect the conversion to be: Remove & return to stock.
Am I getting the correct results, or what am I missing?
Thanks.
- See the Wikipedia link I posted, one way is &
- olafhelperBronze Contributor
Doug_Marquardt , & is just a different (decimal) encoding of & = ampersand.
See List of XML and HTML character entity references - Wikipedia
- Doug_MarquardtCopper 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 character
So how do I represent & as part of the node text?
- olafhelperBronze ContributorSee the Wikipedia link I posted, one way is &