• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Extraction of CData Part and later its embedding

 
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Could someone please help me figure out how I can extract from my xml the CData part, which is also an xml. Once I have the CData xml, I will then apply some xslt script on it and then embed the processed xml back in the CData area.

For example:




I would like to extract the

<CreditCardNumber>123456123</CreditCardNumber>

, process it with my xslt script and then embed it back in the original xml, e.g. my desired out:



The masking

<CreditCardNumber>*******23</CreditCardNumber>

above is done by my xslt script.

What I need to know is how I can extract the CData part and embedd it back.

Second important thing is that the structure of my input xml is not fix. The input xml could vary in structure, i.e. it might or might not have CData, incase if the CData is not there, the xslt script should simply be applied and masking is performed if required. The masking logic is handled entirely in the xslt script. But in-case, if the CData is present, then the extraction->xslt script->embed logic is applied.

A pure xslt based solution is not feseable, but some java and xslt solution.

So in short, I am looking for a kind osolution as to how I can check if CData is present, and if yes, extract its contents, then xslt and then embedding it back in the original xml.

Thanks.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, as far as the parser is concerned, your CDATA section is just treated as a string. So you extract it by the trivial operation of getting a text node. Whether you can tell whether it's a CDATA section or not, I don't know, but you should ignore that requirement because CDATA is just a convenience for producers of documents who don't want to deal with escaping. It's not meant to have syntactic significance.

Then you just do your XSLT on the string you extracted and produce a new string as the result of the transformation. You put that string back using the trivial operation of setting a text node. (By the way I assume you were using DOM for this, since you said you weren't using XSLT, but the same would apply if you were using a SAX filter process.)

If you're using an identity transformation to convert your DOM to a document and you're stuck with the incorrect requirement of producing a CDATA section for that element, then I believe the <xsl:output> element has an attribute which allows you to specify which elements should be output as CDATA. So instead use a transformation which is the identity transformation with an <xsl:output> element like that.
 
Norman Meister
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i did it finally with plain xslt based solution.

thanks anyway.
 
Eat that pie! EAT IT! Now read this tiny ad. READ IT!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic