[jdom-interest] RE: XML Syntax Suggestion

Jon Baer jonbaer at digitalanywhere.com
Sun Jan 21 13:42:31 PST 2001


Oops, never clear the attribCount, should be:

SAXBuilder builder = new SAXBuilder();
Document doc = builder.build("mylist.xml");

   int entryCount = 0; int attribCount = 0;
   Element list = doc.getRootElement(); // list
   List entries = list.getChildren("entry"); // entry
   Iterator i = entries.iterator();
   while (i.hasNext()) {
    entryCount++;
    attribCount = 0; // clear attribCount for next Element
    Element e = (Element)i.next();
    List attribs = e.getChildren("attrib"); // attrib
    Iterator a = attribs.iterator();
    while (a.hasNext()) {
     attribCount++;
     Element attrib = (Element)a.next();
     System.out.println("Entry: " + entryCount);
     System.out.println("Attrib: " + attribCount);
     System.out.println("Name: " + attrib.getAttributeValue("name"));
     System.out.println("Value: " + attrib.getAttributeValue("value"));
    }
   }




More information about the jdom-interest mailing list