There may be a bug in the "elementIterator()" method of the classe
"Element".
The contents of my test and results are below which were sent to the list
hours ago.



Hy guys.
I'm having a weird problem in removing a certain element.
My XML doc is ("teste.xml"):

<?xml version='1.0' encoding='ISO-8859-1'?>
<!DOCTYPE CLIENTES SYSTEM 'teste.dtd'>

<CLIENTES>
  <CLIENTE id='1'>
    <NOME valor='Mike'/>
    <MORADA valor='xxx'/>
  </CLIENTE>
  <CLIENTE id='2'>
    <NOME valor='Neca'/>
    <MORADA valor='Aveiro'/>
  </CLIENTE>
</CLIENTES>

---------------------------------
And I have a class like:
---------------------------------

import java.util.Iterator;

import java.net.MalformedURLException;

import java.io.*;

import org.dom4j.*;
import org.dom4j.io.*;

public class Teste {
  public static void main(String[] args) {
    Document doc = null;

    try {
      SAXReader reader = new SAXReader();
      doc = reader.read(new File("teste.xml"));
    } catch(MalformedURLException e) {
      System.out.println(e.getMessage());

    } catch(DocumentException e) {
      System.out.println(e.getMessage());
    }

    Element root = doc.getRootElement();

    for(Iterator i = root.elementIterator(); i.hasNext();) {
      Element elem = (Element)i.next();
      for(Iterator j = elem.attributeIterator(); j.hasNext();) {
        Attribute att = (Attribute)j.next();
        if(att.getValue().equals("1")) {
          i.remove();
        }
      }
    }

    try {
      // Pretty print the document
      OutputFormat format = OutputFormat.createPrettyPrint();
      XMLWriter writer = new XMLWriter(System.out, format);
      writer.write(doc);
      writer.close();

    } catch(IOException e) {
      System.out.println(e.getMessage());
    }
  }
}

---------------------------------
And the weird result is:
---------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE CLIENTES SYSTEM "teste.dtd">

<CLIENTES>
  <CLIENTE id="1">
    <NOME valor="Mike"/>
    <MORADA valor="xxx"/>
  </CLIENTE>
</CLIENTES>

If I'm trying to remove a "CLIENTE" with attribute "id" equals to "1", why
is it the output!?!?
Please help.


-------------------------------------------------------
This sf.net email is sponsored by: viaVerio will pay you up to
$1,000 for every account that you consolidate with us.
http://ad.doubleclick.net/clk;4749864;7604308;v?
http://www.viaverio.com/consolidator/osdn.cfm
_______________________________________________
dom4j-dev mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-dev


-------------------------------------------------------
This sf.net email is sponsored by: viaVerio will pay you up to
$1,000 for every account that you consolidate with us.
http://ad.doubleclick.net/clk;4749864;7604308;v?
http://www.viaverio.com/consolidator/osdn.cfm
_______________________________________________
dom4j-dev mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-dev

Reply via email to