Using xquery to select a node's inner xml as a string when it contains an html image tag



I have an xml field that I need to select the inner xml from a node as a string regardless of what the inner xml is (in this case, it's an html image tag). I'm able to get plain text with no problems but when I have something with the image tag in it, I think it's treating it as a child node so it's not returning it.



declare @myXml xml = '<question><prompt><img src="someImage.png" /></prompt></question>';

select q.value('(prompt/text())[1]', 'nvarchar(max)') as prompt from @myXml.nodes('//question') qs(q);


The above is returning null. What I'm wanting is the actual contents of the node as a string.


No comments:

Post a Comment