How to keep HTML tags in FOR XML query

Lewis Corcoran 26 Reputation points
2023-04-12T08:30:27.7966667+00:00

I need to upload a XML file with HTML code within it. I use the FOR XML PATH at the end of the query, the table has the relevant <p> <p>and </p>tags, but when i click on my result these have been converted to their Unicode values as &lt; and &gt; How do i export these as the raw tags as %lt; is being recognised as the character < and > and not the <p> </p> tag

SQL Server | Other
{count} votes

3 answers

Sort by: Most helpful
  1. Anonymous
    2023-04-12T08:48:33.64+00:00

    Hi @Lewis Corcoran I'm not an expert on XML. Can this thread help you? https://stackoverflow.com/questions/10875577/how-do-you-keep-html-tags-when-querying-a-xml-using-sql Best regards, Percy Tang

    1 person found this answer helpful.
    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Olaf Helper 47,436 Reputation points
    2023-04-13T06:23:26.8466667+00:00

    HTML is nothing else then XML with predefined tags. You can not have XML code within XML code. The only way is to use a CDATA element: https://learn.microsoft.com/en-us/sql/relational-databases/xml/example-specifying-the-cdata-directive?view=sql-server-ver16

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.