You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by minimalism <tk...@gospodinov.net> on 2010/08/13 23:29:16 UTC

Removing an XML element

I searched the forums for a solution to the problem I am having, but I could
not find anything that would work for me. I have an xml file that has nested
elements. A very simplified example would be:
<code><pre>
<body>
    <paragraph font="Verdana">
        <text size = "2">Line1</text>
        <text size = "1">Line2</text>
        <text>Line3</text>
    </paragraph>
</body>
</pre></code>

I want to remove line 2 above. I do this:

<code><pre>
body.getParagraphArray(0).removeText(1);
</pre></code>

This did not work. Am I missing something?

Thanks for your help in advance.
-- 
View this message in context: http://old.nabble.com/Removing-an-XML-element-tp29433197p29433197.html
Sent from the Xml Beans - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: Removing an XML element

Posted by Alexander Mischur <a....@googlemail.com>.
It works fine for me.
maybe you can give some more informations.

I attached a simple example for eclipse.
Note:
At first run build.xml with an Ant [define folder of your xmlbeans-libs in
build.xml]
then open project in eclipe [define variable for xmlbeans-libs]

-Alex

On Tue, Aug 17, 2010 at 9:30 PM, Duane Zamrok <za...@cubrc.org> wrote:

> Did the code execute without issue and just not work, or did it throw an
> exception of some sort?
>
> I've never really tried removing an element from my XMLObject hierarchy,
> but when I add elements I do the exact same kind of thing. Perhaps you could
> try something like the following. (fair warning this code is off the hip and
> not optimized or tested)
>
> Text[] newArray = body.getParagraphArray(0).getTextArray();
> for(int index =1; index < newArray.length - 1; index++)
>        newArray[index] = newArray[index + 1];
> body.getParagraphArray(0).setTextArray(newArray);
>
>
> -Duane
>
>
> -----Original Message-----
> From: minimalism [mailto:tk@gospodinov.net]
> Sent: Friday, August 13, 2010 5:29 PM
> To: user@xmlbeans.apache.org
> Subject: Removing an XML element
>
>
> I searched the forums for a solution to the problem I am having, but I
> could
> not find anything that would work for me. I have an xml file that has
> nested
> elements. A very simplified example would be:
> <code><pre>
> <body>
>    <paragraph font="Verdana">
>        <text size = "2">Line1</text>
>        <text size = "1">Line2</text>
>        <text>Line3</text>
>    </paragraph>
> </body>
> </pre></code>
>
> I want to remove line 2 above. I do this:
>
> <code><pre>
> body.getParagraphArray(0).removeText(1);
> </pre></code>
>
> This did not work. Am I missing something?
>
> Thanks for your help in advance.
> --
> View this message in context:
> http://old.nabble.com/Removing-an-XML-element-tp29433197p29433197.html
> Sent from the Xml Beans - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>

RE: Removing an XML element

Posted by Duane Zamrok <za...@cubrc.org>.
Did the code execute without issue and just not work, or did it throw an exception of some sort?

I've never really tried removing an element from my XMLObject hierarchy, but when I add elements I do the exact same kind of thing. Perhaps you could try something like the following. (fair warning this code is off the hip and not optimized or tested)

Text[] newArray = body.getParagraphArray(0).getTextArray();
for(int index =1; index < newArray.length - 1; index++)
        newArray[index] = newArray[index + 1];
body.getParagraphArray(0).setTextArray(newArray);


-Duane


-----Original Message-----
From: minimalism [mailto:tk@gospodinov.net]
Sent: Friday, August 13, 2010 5:29 PM
To: user@xmlbeans.apache.org
Subject: Removing an XML element


I searched the forums for a solution to the problem I am having, but I could
not find anything that would work for me. I have an xml file that has nested
elements. A very simplified example would be:
<code><pre>
<body>
    <paragraph font="Verdana">
        <text size = "2">Line1</text>
        <text size = "1">Line2</text>
        <text>Line3</text>
    </paragraph>
</body>
</pre></code>

I want to remove line 2 above. I do this:

<code><pre>
body.getParagraphArray(0).removeText(1);
</pre></code>

This did not work. Am I missing something?

Thanks for your help in advance.
--
View this message in context: http://old.nabble.com/Removing-an-XML-element-tp29433197p29433197.html
Sent from the Xml Beans - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org