|
Hey Doug
The first thing is to find the Element which is
going to be the parent to which you are going to add a new element. The
selectSingleNode() returns a Node because you could be finding the document
("/") or an attribute ("/foo/@x"), a namespace node
("namespace::*") or text node (":/foo/bar/text()"etc
So you just need to cast it if you know, from the
XPath expression, that its going to be an Element.
e.g.
Element parent = (Element) doc.selectSingleNode(
"//server_request/server/weblogic/internal"
);
// add a new element
parent.addElement( "server_address" ).addText( "192.10.20.41" );
The last add line could be more verbose if you
wish. e.g.
Element serverAddress = parent.addElement(
"server_address" );
serverAddress.addText( "192.10.20.41"
);
James
|
Title: Message
- [dom4j-user] Adding a node to the middle of a pre-existing ... Doug Hoppes
- [dom4j-user] Exception getting SAX parser James Strachan
- [dom4j-user] Exception getting SAX parser David Hooker
- Re: [dom4j-user] Exception getting SAX parser James Strachan
- RE: [dom4j-user] Exception getting SAX parser David Hooker
- Fwd: [dom4j-user] Adding a node to the middle of a pre... Peter Schaefer
- Re: [dom4j-user] Adding a node to the middle of a ... James Strachan
