0

I am trying create Java Servlet which will modify existing XML.

This a part of my orginal XML:

<customfieldvalues>
<div id="errorDiv" style="display:none;"/>
<![CDATA[ 
 Vinduer, dører
 ]]>
</customfieldvalues>

I want to get the following result:

<customfieldvalues>
<div id="errorDiv" style="display:none;"/>
Vinduer, d&#248;rer
</customfieldvalues>

I iterate over the XML structure with:

Document doc = parseXML(connection.getInputStream());
NodeList descNodes = doc.getElementsByTagName("customfieldvalues");
for (int i=0; i<descNodes.getLength();i++) {
    Node node = descNodes.item(i);
    // how to ?
}   

So, I need to remove CDATA and convert the content. I saw that I can use this for the conversion.

javalonde
  • 549
  • 2
  • 6
  • 7
  • This is has a partial answer in http://stackoverflow.com/questions/2067116/convert-an-xml-element-whose-content-is-inside-cdata – Oded Peer Oct 16 '12 at 07:45

1 Answers1

1

javax.xml.parsers.DocumentBuilderFactory.setCoalescing API

  • Specifies that the parser produced by this code will
  • convert CDATA nodes to Text nodes and append it to the
  • adjacent (if any) text node. By default the value of this is set to
  • false
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275