[jdom-interest] help? inserting content into xml file

Robert Koberg rob at koberg.com
Sat Apr 28 11:47:33 PDT 2001


It seems like it is the wrong time to be asking questions around here. Is
there a better list to ask questions about jdom?

If this is that list then:
how do I get a reference to a parent node located anywhere in the doc so I
can add a child to it? The only info I have about the parent node is it's
unique id attribute value.

I was hoping something like below would work but it does not because the
result of the xpath is not an element in the doc.  How can I make this
happen? Any suggestions would be welcome.

public synchronized void saveConfiguration(OutputStream out)
        throws IOException {

         Element root = doc.getRootElement();

         XPath xpath = new XPath("//*[@id='" + parentElementID + "']");

         ContextSupport helper = new ContextSupport();

         helper.setFunctionContext( XPathFunctionContext.getInstance() );

         Object parentNode = xpath.applyTo(root);

         parentNode.addChild(new Element("page").addContent("blow me"));

         XMLOutputter fmt = new XMLOutputter();
         fmt.output(doc, out);


More information about the jdom-interest mailing list