• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

XML Entity reference

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
We don't have time for this. We've gotta save the moon! Or check this out:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic