Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7016493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:47:33+00:00 2026-05-27T22:47:33+00:00

How to store a string which is already an xml, as an attribute of

  • 0

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 &lt; and &gt; etc.

This is the query I am using:

select @OutputXml=(select @inputXmlString as '@oneViewXml'
for xml path('root'))

This is the output:

<root oneViewXml="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&#xD;&#xA;&lt;OneViewReviewRq&#xD;&#xA;    xmlns:xsi = &quot;http://www.w3.org/2001/XMLSchema-instance&quot;&#xD;&#xA;    xmlns:xsd = &quot;http://www.w3.org/2001/XMLSchema&quot;&gt;&#xD;&#xA;&lt;LOAN&gt;ASFDK&lt;/LOAN&gt;&#xD;&#xA;&lt;/OneViewReviewRq&gt;" />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:47:34+00:00Added an answer on May 27, 2026 at 10:47 pm

    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:

    declare @inputXmlString nvarchar(max) = 
    '<?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>'
    
    declare @OutputXml xml
    
    select @OutputXml=(select @inputXmlString as '@oneViewXml'
    for xml path('root'))
    
    select @OutputXml.value('root[1]/@oneViewXml', 'nvarchar(max)')
    

    https://data.stackexchange.com/stackoverflow/qt/123198/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a char pointer which would be used to store a string. It
I want to store a string in memory and read it later: $$->desc.constant->base.id =
Suppose I have a string 'johndoe@hotmail.com' . I want to store the string before
I need to store in my object which values have already been handlerd, I
I have a single java bean, which is already annotated for JPA, that I
I'm using Windows Forms and VS2008. I want to store an enum value in
I am trying to pass a string that already contains quotation marks from one
I want to write a stored procedure that queries XML files after I have
I have a variable, emailBody, which is set to a string stored in a
ok so my issue is i have the string '\222\222\223\225' which is stored as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.