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:

&lt;root&gt;   &lt;importdata&gt;dat&lt;/importdata&gt;   &lt;response&gt;    <![cdata[&lt;secondroot&gt;    &lt;data&gt;123&lt;/data&gt;    &lt;dataescapedcharacterincluded&gt; 3 &gt; 1&lt;/dataescapedcharacterincluded&gt;    &lt;/secondroot&gt;]]>   &lt;/response&gt; &lt;/root&gt; 

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 &gt; 1</dataescapedcharacterincluded>       </secondroot>      </response>   <root> 

the data show may not escaped. if unescape it, may yield not well-formed xml. consider line:

&lt;dataescapedcharacterincluded&gt; 3 &gt; 1&lt;/dataescapedcharacterincluded&gt; 

if unescape it, become this:

<dataescapedcharacterincluded> 3 > 1</dataescapedcharacterincluded> 

this still valid (a greater-than not need escaped), assume you'll have &lt; 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 set yes, , 1 actual transformation.
  • use extension function takes string , returns node set.
  • with xslt 3.0, use new function fn:parse-xml or fn: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[&lt;root&gt;bla&lt;/root&gt;]]></elem> 

it doubly escaped. in latter case, need unescape cycle before can process it.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -