getagrip
2010-12-20 19:12:29 UTC
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
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