c# - escaped xml with cdata that has also has both escaped data value and tags -
i receiving xml data web service returns data 1 escaped xml string. whatever reason, part of xml enclosed within cdata tag. escape xml within cdata contain escaped xml character well. example:
<root> <importdata>dat</importdata> <response> <![cdata[<secondroot> <data>123</data> <dataescapedcharacterincluded> 3 > 1</dataescapedcharacterincluded> </secondroot>]]> </response> </root>
i need transform both xml inside , out of cdata section xml format xsl, i'm having hard time figuring out how usable xml form either c# or xsl can xsl transform different format. below:
<root> <importdata>dat</importdata> <response> <secondroot> <data>123</data> <dataescapedcharacterincluded> 3 > 1</dataescapedcharacterincluded> </secondroot> </response> <root>
the data show may not escaped. if unescape it, may yield not well-formed xml. consider line:
<dataescapedcharacterincluded> 3 > 1</dataescapedcharacterincluded>
if unescape it, become this:
<dataescapedcharacterincluded> 3 > 1</dataescapedcharacterincluded>
this still valid (a greater-than not need escaped), assume you'll have <
in there somewhere, must escaped. if doubly escaped should fine.
to transform there several things can do:
- with xslt 1.0 or 2.0, transform in 2 passes, 1 unescaping
disable-output-escaping
setyes
, , 1 actual transformation. - use extension function takes string , returns node set.
- with xslt 3.0, use new function
fn:parse-xml
orfn:parse-xml-fragment
, can take xml-as-a-string input. - if entire source escaped, looks like, feed unescaped xslt processor explained here. take care of escaped cdata (but part remain escaped, see below).
what not entirely clear post whether doubly escaped. i.e., if data looks this:
<elem><![cdata[<root>bla</root>]]></elem>
it singly escaped. if looks this:
<elem><![cdata[<root>bla</root>]]></elem>
it doubly escaped. in latter case, need unescape cycle before can process it.
Comments
Post a Comment