0

As the question title says, I am trying to wrap a SELECT statement in SQL Server with CDATA without using FOR XML EXPLICIT. I currently use FOR XML PATH, like so:

SELECT p.SKU AS [BasicInfo/SellerPartNumber]
FOR XML PATH('Item')

I know that I can convert this to FOR XML EXPLICIT and wrap in a CDATA, but is there a purely SQL way to wrap this in CDATA apart from just concatenating?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Codeman
  • 12,157
  • 10
  • 53
  • 91
  • 1
    FOR XML EXPLICIT is the only way I know of. Once you have the XML in the XML data type in SQL Server the CDATA sections is removed and the content entitized. Just curious, why do you need the CDATA sections? There is as far as I know no situation where you can't create the same XML using entities instead. – Mikael Eriksson Jan 09 '15 at 06:45
  • @MikaelEriksson I ended up doing it in the C# - it just seemed cleaner to do all of it in the SQL on generation, rather than using LINQ-XML to modify it on the fly. If you'd like to add an answer that says "no, that is impossible", please do so, otherwise I'll add what I ended up doing. – Codeman Jan 12 '15 at 19:42
  • Closed as dupe instead. The question is perhaps not an exact duplicate but the answer would be :). If you are unhappy with that please let me know and can reopen the question again. – Mikael Eriksson Jan 13 '15 at 06:49
  • 1
    @MikaelEriksson sounds good, hopefully people asking the same question will find their answer - "No" :) – Codeman Jan 13 '15 at 18:38

0 Answers0