How to store a string which is already an xml, as an attribute of a root node of another xml?
The string that I want to store is @inputXmlString. It’s value is :
<?xml version="1.0" encoding="utf-8"?>
<OneViewReviewRq
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
<LOAN>ASFDK</LOAN>
</OneViewReviewRq>
I have to store this value as an attribute to another node say row, which is the root node. This is what the desired output should be:
<root oneViewXml="<?xml version="1.0" encoding="utf-8"?>
<OneViewReviewRq
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
<LOAN>ASFDK</LOAN>
</OneViewReviewRq>" />
The problem is: when I use for xml path or for xml raw the quotes and < , > characters are not rendered as is but as < and > etc.
This is the query I am using:
select @OutputXml=(select @inputXmlString as '@oneViewXml'
for xml path('root'))
This is the output:
<root oneViewXml="<?xml version="1.0" encoding="utf-8"?>
<OneViewReviewRq
 xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
<LOAN>ASFDK</LOAN>
</OneViewReviewRq>" />
That is exactly as it should be because
<>&are invalid characters in XML attributes. When you query your XML for the attribute value you will get the XML back as it was.Try this:
https://data.stackexchange.com/stackoverflow/qt/123198/