[jdom-interest] RE: XML Syntax Suggestion

Jon Baer jonbaer at digitalanywhere.com
Sun Jan 21 13:23:38 PST 2001


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++;
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"));
    }
}

"Dodson, John" wrote:

> Did anyone get this? Help please! =-}
>
> -----Original Message-----
> From: Dodson, John
> Sent: Thursday, January 18, 2001 3:12 PM
> To: 'Jason Hunter'
> Cc: 'jdom-interest at jdom.org'
> Subject: RE: XML Syntax Suggestion
>
> Resend...now that I'm a JDOM member
>
> Hey,
>
> I'm fairly new to JDOM and XML, and would like to solicit advice.  I want to
> create a generic list syntax that will be easy to parse.  I'm thinking
> something like what follows.
>
> 1. Does this sound reasonable or is there an easier way?
> 2. How easy would this be to parse with JDOM?
>
> <list>
>         <entry>
>                 <attrib name="eventType" value="info"/>
>         </entry>
>         <entry>
>                 <attrib name="eventSsName" value="NI"/>
>                 <attrib name="eventSeverity" value="fatal"/>
>         </entry>
> </list>
>
> Thanks very much in advance,
>
> John Dodson
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com




More information about the jdom-interest mailing list