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 949725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:26:51+00:00 2026-05-15T23:26:51+00:00

Is there a way to get the xml-safe version of an xml column in

  • 0

Is there a way to get the xml-safe version of an xml column in sql server ?

By xml-Safe i mean escaping special characters like <,>,’, &, etc.

I’d like to avoid doing the replacements myself. Is there a build in function in sql server.

What I want to achieve is to store the xml content into another xml attribute.

  • 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-15T23:26:51+00:00Added an answer on May 15, 2026 at 11:26 pm

    I assume that by xml-safe you mean escaping of XML special tags. If you have an XML column you wish to include in another XML document then you have two options:

    • project the column as [*]: select ..., xmlcolumn as [*], ... from ... for xml path... this will embed the XML content of the column in the result XMl. Eg. if the column has the value <element>value</element> then the result will be like <root><row><element>value</element></row></root>.
    • project the column as the column name: select ..., xmlcolumn, ... from ... for xml path... this will insert the content of the column as a value (ie. it will escape it). Eg. the same value as above will produce <root><row><xmlcolumn>&lt;element&gt;&lt;value&lt;/element&gt;.

    If your question is about something else, then you’re going to have to rephrase it in a proper manner and use terms correctly. Don’t invent new terms no one understands but you.

    Update:

    If you are inserting XML values into the column, then you don’t have to do anything at all. The client libraries know how to handle the proper escaping. As long as you write your code correctly. Remeber, XML is NOT a string and should never, ever be treated as one. If you write XML in your client, use an appropriate XML library (XmlWriter, XML DOM, Linq to XML etc). when passing in the XML into SQL Server, use the appropiate type: SqlXml. Stored procedures should use the appropiate parameter type: XML. When you read it, use the appropriate method to read XML: GetSqlXml(). Same goes for declaring the type in one of the miriad designers (LINQ to SQL , EF etc). Ultimately, there is never any need to escape XML characters manually. If you find yourself doing that, you’re using the wrong API and you have to go back to the drawing board.

    A good start reading is XML Support in Microsoft SQL Server 2005.

    And finally, to manipulate XML as you describe (update XML column of table A with XML column of table B), you use XML methods, specifically modify (… insert…), and you bind the table B column inside the XQuery using sql:column:

    update A
    set somecolumn.modify('insert {sql:column("B.othercolumn")} before somenode')
    from A join B on ...;
    

    In you comment you threat XML as a string and, as I already said, you should never ever do that: strings and XML are as water and oil.

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

Sidebar

Related Questions

Is there a way to get stored procedures from a SQL Server 2005 Express
Is there a way to get the current xml data when we make our
is there way how to get name ov event from Lambda expression like with
Is there a way to get a screenshot of a glade/gtkbuilder UI xml by
Is there a way to get raw XML which is generated by SOAP request
Is there a way to get this XML from select * from ANY_TABLE query?
Is there a way to get the name of an attribute of an XML
Is there a way to get the number of strings in my strings.xml or
Is there any way to get the xml encoding in the toString() Function? Example:
Is there any way to get the xml serializer to convert the following: class

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.