Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] how to add item to existing node?

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: getagrip <getagrip AT web.de>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] how to add item to existing node?
  • Date: Mon, 20 Dec 2010 20:12:29 +0100

Hi, I am trying to figure out how to add children to a Node after having used the Node.query() method:

<roles>
<role id="employee">
<user>bob</user>
<user>sally</user>
</role>
<role id="boss"/>
</roles>

Here's the query:

val roles = doc.query("/roles/role")

val role = roles.get(0)
val users = role.query("user")
users.get(0).detach // bob is removed

Now I would like to ADD a node/element to the <role id="boss"/> Node.
Something like this:

roles.get(1).attach(new Element("user").addChild("myself"))

Appart from having a detach() method there is no attach()-method though :-(

Also I would need to have a ParentNode to add a child but in my case as you can see the <role id="boss"/> node is empty.

How can I add a child node here? Do I have to iterate the whole Document again using "Element"?
But then I would have to explicitly parse every single node and write it back to the doc which would be too tedious.

Thanks for hints, getagrip





Archive powered by MHonArc 2.6.24.

Top of Page