Hi Wendy;
Thanks for you help.
Is this along the lines of what you were thinking (see below)? All the
methods being called now are defined in the XMLParser class.
I am getting a NullPointerException right now, I am in the midst of
improving my debugging to determine where it is occuring.
Thanks,
Luke
import java.io.File;
import java.io.IOException;
import java.util.TreeMap;
import java.util.Vector;
//Digester imports
import org.apache.commons.digester.Digester;
import org.xml.sax.SAXException;
/**
* @author lshannon
* @since November 2004
* The XMLParser takes a File object (must contain a xml file type).
* This class is part used in the FutureBrand CMS system. It is generally
* used in the XMLDocument class.
*/
public class XMLParser {
private TreeMap fieldsValues;
private Digester digester;
private File parseMe;
private String name;
/**
* This returns a reference to the XMLParser ready to extract
* content from the File file.
* @param file This file should reference an XML type file
*/
public XMLParser(File file) {
parseMe = file;
}
/**
* This class returns a TreeMap containing the content found in
* all the <item> nodes of the document (key= @NAME, value= node contents).
* @return A TreeMap containing a key/value pairing for each item node of
a default.xml document
* @throws IOException
* @throws SAXException
*/
public TreeMap digest() throws IOException, SAXException {
digester = new Digester();
digester.setValidating(false);
digester.addObjectCreate("DATA/VERSION", "createTreeMap");
digester.addSetProperties("DATA/VERSION/ITEM", "NAME", "name");
digester.addCallMethod("DATA/VERSION/ITEM", "addItem", 0);
return fieldsValues;
}
public void createTreeMap() {
fieldsValues = new TreeMap();
}
public void addItem(String value) {
Trace.ENTER("Inserting " + getName() + " " + value + " in to the main
map");
fieldsValues.put(getName(), value);
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
----- Original Message -----
From: "Wendy Smoak" <[EMAIL PROTECTED]>
To: "Jakarta Commons Users List" <[email protected]>
Sent: Tuesday, February 01, 2005 2:32 PM
Subject: Re: Need a little help
> From: "Luke Shannon" <[EMAIL PROTECTED]>
> > I have done away with the Version.class and decided to build my
collection
> > of Item maps within the class that calls the digester methods (a full
> > description of my code can be seen below). My problem now is using the
> > addSetNext method to call a local method.
>
> Why is there a TreeMap inside Item? It doesn't look [to me] like you need
> an Item class at all, you could create a TreeMap when you hit <VERSION>
and
> add key/value pairs directly to it when you see <ITEM> tags.
>
> You wrote:
> > > To review, the end result was to get a TreeMap containing all the name
> > > attributes as keys and the contents of the item tags as values from a
> > > directory of XML files
>
> --
> Wendy Smoak
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]