Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Looking for a better way to extract the CDATA elments

843834Aug 24 2006 — edited Aug 28 2006
I'm trying to use the following to create a document :
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

factory.setValidating(false);
factory.setNamespaceAware(false);

// Create the builder and parse the file
Document doc = factory.newDocumentBuilder().parse(f);

is there something else I need to parse the document correctly? The reason I ask is because, once the element is isolated that contains the necessary information, I'm having to use the following to extract the contents from the CDATA section:
value.addElement(objElmProp.getFirstChild().getNextSibling().getFirstChild().getNodeValue());

The element structure looks like this (Note: I have no control or input over how this element is created):

<property name="propertyValue">
<string><![CDATA[$USER_HOME$$/$MYDIR]]></string>
</property>

objElmProp.getNodeName() finds 'property' which is the above CDATA_SECTION_NODE, but contains useless information for the value ('\n\t\t\t\t\t' is what this element contains for value). In addition, any children are also null or garbage characters.

Another reason I believe there is an issue is because I cannot get changes made to the instance to show up in a new document using the following approach:
// Write the DOM document to the file
Transformer xformer = TransformerFactory.newInstance().newTransformer();
Result result = new StreamResult(new FileOutputStream(file));
xformer.transform(source, result);


I'd appreciate any assistance you can provide.
Thanks,
Sean
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 25 2006
Added on Aug 24 2006
4 comments
242 views