hi carlos,

your code looks correct, I do the deletion of Elements in a way like this
and it works. i could imagine two things
to try:

As I can see in the Exception you got, I suppose you're using jdom-b8
(because as I think, FilterLists do not exist before b8).
Perhaps it's a jdom-based problem, just try your code with jdom-b7 - it's a
very stable version.

The second thing you could try is to retrieve the Elements in another way
than getChildren()  and the Iterator() to avoid the Exception (but this is
really
only an assumption), just try to retrieve the Elements by XPath like this:

[...]

XPath xpath = new XPath("/node()[@name='reporter']");

List result = xpath.selectNodes(jdomDoc);

for (int i=0;i<result.size();i++)
     ((Element)result.get(i)).detach();

[...]


Perhaps this helps to avoid the invocation of the method throwing the
exception:
 org.jdom.ContentList$FilterListIterator.checkConcurrentModification


hope this helps,
hans




                                                                                       
                                                             
                    Carlos Barroso                                                     
                                                             
                    <est-c-barroso@ptin        An:     'Hans Prüller' 
<[EMAIL PROTECTED]>                                                        
                    ovacao.pt>                 Kopie:                                  
                                                             
                                               Thema:  RE: Antwort: [Jaxen] Remove an 
element from a document...                                    
                    09.04.2002 15:52                                                   
                                                             
                                                                                       
                                                             
                                                                                       
                                                             



Thanks for the advice, but with this simple code:


import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;

import org.jaxen.jdom.XPath;

import org.jaxen.XPathSyntaxException;
import org.jaxen.JaxenException;

import java.util.List;
import java.util.Iterator;

import java.io.*;

public class JDOMDemo {
    public static void main(String[] args) {
        try {
            SAXBuilder builder = new SAXBuilder();
            Document doc = builder.build( "signon.xml" );
            Element root = doc.getRootElement();
                 List kids = root.getChildren();
                 Iterator it = kids.iterator();
                 while(it.hasNext()) {
                   Element elem = (Element)it.next();
                   if(elem.getAttributeValue("name").equals("reporter")) {
                         elem.detach();
              }
            }

               XMLOutputter out = new XMLOutputter();
               out.setIndent("  ");
               out.setNewlines(true);
               out.output(doc, System.out);

        } catch (JDOMException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

I get the following exception:

java.util.ConcurrentModification
           at
org.jdom.ContentList$FilterListIterator.checkConcurrentModification(...)
           at org.jdom.ContentList$FilterListIterator.hasNext(...)
           at JDOMDemo.main(...)

This is a simple program that reads the content of a XML file("signon.xml")
and when it get's elements where the attribute "name" has the value
"reporter"
it "detaches" the element from the document tree. But I can't find the
problem...
Can you help me? Thanks.

-----Original Message-----
From: Hans Prüller [mailto:[EMAIL PROTECTED]]
Sent: terça-feira, 9 de Abril de 2002 15:38
To: Carlos Barroso
Cc: [EMAIL PROTECTED]
Subject: Antwort: [Jaxen] Remove an element from a document...



Hi,

if you're using Jaxen with JDOM you just need to call the Element.detach()
method and the Element and its descendants
will be removed from the tree.

regards,
hans



|--------+------------------------------------------>
|        |          Carlos Barroso                  |
|        |          <[EMAIL PROTECTED]>   |
|        |          Gesendet von:                   |
|        |          [EMAIL PROTECTED]|
|        |          eforge.net                      |
|        |                                          |
|        |                                          |
|        |          09.04.2002 15:03                |
|        |                                          |
|--------+------------------------------------------>

>
---------------------------------------------------------------------------
--------------------------------|
  |
|
  |       An:     "'[EMAIL PROTECTED]'"
<[EMAIL PROTECTED]>             |
  |       Kopie:
|
  |       Thema:  [Jaxen] Remove an element from a document...
|

>
---------------------------------------------------------------------------
--------------------------------|



Hy guys. Does any one knows how to remove an element(including all it's
decendants)
from a document in one step?


_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest




____________________________________________________
IGS Systemmanagement
GmbH & Co KG
Dorfplatz 5
A-4531 Piberbach
phone: +43 7228 6451 0       home: http://www.igs.at
fax: +43 7228 6451 30        eMail: [EMAIL PROTECTED]
hotline:
fax: +43 7228 6451 20        eMail: [EMAIL PROTECTED]
____________________________________________________

NEWSFLASH___________________________________________

DKC Dokumentation ab sofort unter www.igs.at
im Downloadbereich verfügbar

Anlagenmanagement ab sofort verfügbar
Reservieren Sie sich Ihren persönlichen Demotermin
unter: [EMAIL PROTECTED]

NEWSFLASH___________________________________________




____________________________________________________
IGS Systemmanagement
GmbH & Co KG
Dorfplatz 5
A-4531 Piberbach
phone: +43 7228 6451 0       home: http://www.igs.at
fax: +43 7228 6451 30        eMail: [EMAIL PROTECTED]
hotline:
fax: +43 7228 6451 20        eMail: [EMAIL PROTECTED]
____________________________________________________

NEWSFLASH___________________________________________

DKC Dokumentation ab sofort unter www.igs.at
im Downloadbereich verfügbar

Anlagenmanagement ab sofort verfügbar
Reservieren Sie sich Ihren persönlichen Demotermin
unter: [EMAIL PROTECTED]

NEWSFLASH___________________________________________


_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest

Reply via email to