This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes XML Entity reference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "XML Entity reference " Watch "XML Entity reference " New topic
Author

XML Entity reference

kasim sert
Greenhorn

Joined: Jul 02, 2010
Posts: 9
Hi all,

When i am adding some new nodes to an existing xml element everything seems fine but new document does not contain entity reference node.Can anybody tell me please why I loose entity reference although i dont make any processing with it ? Do i need to set some attribute not to loose it ?

here is my code;

doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("myxml.xml");

XPath xpath = XPathFactory.newInstance().newXPath();
NodeList nodes = (NodeList)xpath.evaluate("//A/B[@name='C']", doc, XPathConstants.NODESET);

Element entry = doc.createElement("entry");
Attr valueAttribute = doc.createAttribute("value");
valueAttribute.setValue("newnode");

// append attribute
entry.setAttributeNode(valueAttribute);
nodes.item(0).appendChild(entry);
// save the result
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.transform(new DOMSource(doc), new StreamResult("myxml.xml"));

Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML Entity reference
 
Similar Threads
XPath expression constrained by a predicate doesn't work (//element[@attribute="value"])
How to update/insert/delete an element from an XML document
XML Paring with quotes in attribute value.
XML file Location
Wrong Document Error when adding deep copy node to new document (Resolved)