Specifying order when adding an element

1 view
Skip to first unread message

Matt Adams

unread,
Oct 22, 2010, 2:26:43 PM10/22/10
to xml...@googlegroups.com
Hello,

Let's say I have an XML document that looks like this:

<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jr="http://openrosa.org/javarosa">
<h:head>
<h:title>replace_with_title</h:title>
<model>
<itext>
</itext>
<instance>
<an_instance_name xmlns="">
<one/>
<three/>
<four/>
</an_instance_name>
</instance>
</model>
</h:head>
<h:body>
</h:body>
</h:html>

Is it possible to insert the element <two/> after <one/> and have it
appear in that order when the XML document is output as a string?

Forgive me if the answer is obvious - I didn't see anything like this in
the manual but I wanted to make sure I wasn't missing anything.


Thanks in advance,

Matt

Mathieu

unread,
Oct 22, 2010, 3:10:52 PM10/22/10
to xmltool
No there's no such thing yet. If you need it, you can checkout the
trunk of xmltool and add a method:

XMLTag.insertBefore(String tageName)

which could do exactly like the addTag method, but use the
Element.insertBefore() method of W3C behind and place the current
cursor to the newly created tag.

I don't have time now to to the patch but if you send me I can
integrate it quickly and release another version also.

What I am wondering is that i would have liked to do in example:

XMLTag tag = ... // goes to tag <three/>
tag.addNextSibling("six").addPreviousSibling("five").addPreviousSibling("foor")

which gives:

<three/>
<four/>
<five/>
<six/>

addPreviousSibling could be implemented using Element.insertBefore()
for addNextSibling, i dont't know... I dont't see any
Element.insertAfter()
Reply all
Reply to author
Forward
0 new messages