How to insert after using XmlCursor?

Michael Bishop <[email protected]> Wed, 23 Oct 2013 14:51:45 -0400
Newsgroups gmane.text.xml.xmlbeans.user
Message-ID <CAAenQJc4xyFfPkwgOOy4So3YDDW1FHgfarraKAc0s2J7L+oNbw@mail.gmail.com>
--089e0115f682430aef04e96d02ad
Content-Type: text/plain; charset=ISO-8859-1

Hello all,

I'm a bit stuck in trying to achieve this with XmlObjects and XmlCursor.
Imagine the following scenario:

<parent>
    <child>Some text</child>
</parent>

I want to insert a new element AFTER the child element.

<parent>
    <child>Some text</child>
    <!-- New element here! -->
</parent>

I don't necessarily know anything about the child element. It might have
child text like the example above. It might not. It might have child
elements, it might not. It might have siblings, it might not. Here's where
I'm stuck:

// XmlObject representing parent.
XmlObject parent = ...;

XmlCursor parentCursor = parent.newCursor();

// Now I'm at the START token for the child element.
parentCursor.toChild("child");

From here, how do I reliably get the cursor past </child> or <child/>?
Basically I'm at the start of <child> and want to be right past the end of
that element.

Thanks,

Michael

--089e0115f682430aef04e96d02ad
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div><div><div><div><div><div><div><div><div>Hello al=
l,<br><br>I&#39;m a bit stuck in trying to achieve this with XmlObjects and=
 XmlCursor. Imagine the following scenario:<br><br></div>&lt;parent&gt;<br>
</div>=A0=A0=A0 &lt;child&gt;Some text&lt;/child&gt;<br></div>&lt;/parent&g=
t;<br><br></div>I want to insert a new element AFTER the child element.<br>=
<br></div>&lt;parent&gt;<br></div>=A0=A0=A0 &lt;child&gt;Some text&lt;/chil=
d&gt;<br>
</div>=A0=A0=A0 &lt;!-- New element here! --&gt;<br></div>&lt;/parent&gt;<b=
r><br></div>I don&#39;t necessarily know anything about the child element. =
It might have child text like the example above. It might not. It might hav=
e child elements, it might not. It might have siblings, it might not. Here&=
#39;s where I&#39;m stuck:<br>
<br></div>// XmlObject representing parent.<br><div>XmlObject parent =3D ..=
.;<br><br></div><div>XmlCursor parentCursor =3D parent.newCursor();<br><br>=
</div><div>// Now I&#39;m at the START token for the child element.<br></di=
v>
<div>parentCursor.toChild(&quot;child&quot;);<br><br></div><div>From here, =
how do I reliably get the cursor past &lt;/child&gt; or &lt;child/&gt;? Bas=
ically I&#39;m at the start of &lt;child&gt; and want to be right past the =
end of that element.<br>
<br>Thanks,<br><br>Michael<br></div></div>

--089e0115f682430aef04e96d02ad--