[jdom-interest] problems with ListIterator

Chris Hamersley chris.hamersley at xmlglobal.com
Thu Aug 31 09:53:36 PDT 2000


Hello,
I tried using some of the ListIterator methods with JDOM such as add and
remove and nothing seemed to happen.  Here is some example code:

Java:
        try
        {
            String filename = args[0];

            SAXBuilder builder = new SAXBuilder();
            Document doc = builder.build(new File(filename));

            Element e = doc.getRootElement();
            ListIterator iterator = e.getChildren().listIterator();
            e = (Element)iterator.next();

//            iterator.remove();

            iterator.add((Element)e.clone());
            iterator.add((Element)e.clone());

            XMLOutputter fmt = new XMLOutputter();
            fmt.output(doc, System.out);
        }
        catch (Exception e) { e.printStackTrace(); }

XML:

<testroot>
	<testchild/>
	<testchild/>
</testroot>


Regards,
Christopher Hamersley




More information about the jdom-interest mailing list