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

  • SEARCH
  • Home
  • 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 7635989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:33:49+00:00 2026-05-31T07:33:49+00:00

I am extracting XML from a table using FOR XML clause. select maincode as

  • 0

I am extracting XML from a table using FOR XML clause.

select
    maincode as cod_deal
    , catcode as cod_category
    , catname as title_category
        ...
from myTable
for xml raw, elements

Some fields contains HTML tags (<span>s). The resulting XML display escaped tags:

&lt;span&gt;my field content&lt;/span&gt;

instead of

<span>my field content</span>

How may I prevent tsql escapes tags?

EDITED.
Note. Wrapping the <![CDATA[...]]> tag around the <span> tag does not do the work. The ‘<‘ and ‘>’ characters of CDATA are escaped as well!!

  • 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-31T07:33:50+00:00Added an answer on May 31, 2026 at 7:33 am

    How may I prevent tsql escapes tags?

    I’m not entirely sure that is what you want. But…

    Sample data:

    declare @T table
    (
      Col varchar(50)
    )
    
    insert into @T values ('<span>my field content 1</span>')
    insert into @T values ('<span>my field content 2</span>')
    

    The equivalent of your query against this table:

    select Col
    from @T
    for xml raw, elements, type
    

    The result from this will be one row and one column that holds a XML document that looks like this:

    <row>
      <Col>&lt;span&gt;my field content 1&lt;/span&gt;</Col>
    </row>
    <row>
      <Col>&lt;span&gt;my field content 2&lt;/span&gt;</Col>
    </row>
    

    This is the way it has to look if you want <span>my field content 1</span> to be the value of element col.

    What you are asking for could be created like this:

    select cast(Col as xml) as Col
    from @T
    for xml raw, elements, type
    

    And this will also return one row with one XML column like this:

    <row>
      <Col>
        <span>my field content 1</span>
      </Col>
    </row>
    <row>
      <Col>
        <span>my field content 2</span>
      </Col>
    </row>
    

    Here you have <span>my field content 1</span> as a child node to Col not as a value.

    If you have your XML escaped you will get the correct values back when you extract them from the XML. Something like this in TSQL but should be the same in other languages.

    declare @X xml
    set @X = 
    '<row>
      <Col>&lt;span&gt;my field content 1&lt;/span&gt;</Col>
    </row>
    <row>
      <Col>&lt;span&gt;my field content 2&lt;/span&gt;</Col>
    </row>'
    
    select T.N.value('Col[1]', 'varchar(50)') as Col
    from @X.nodes('/row') as T(N)
    

    Result:

    Col
    --------------------------------------------------
    <span>my field content 1</span>
    <span>my field content 2</span>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am extracting data from web service(xml file) using NSXmlParser.How can I write to
I have an xml file from which I am extracting html using LINQ to
I am extracting data from XML using XSLT 2.0. The data has long lines
I'm extracting files from zip and rar archives into raw buffers. I created the
I'm extracting XML node from an XElement. When I use XElement.Value it strips any
I am using this code to retrieve the values I want from XML: IEnumerable<ForewordReview>
I'm extracting some information from an XML file, and I want to perform some
I'm extracting some xml from an XFA static form. Here is a sample: <xfa:datasets
Extracting data from XML I want to preprocess one before sending it as a
I am new to perl. I am extracting some nodes information from xml file

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.