[jdom-interest] help with newbie question

Alex Colic acolic at yahoo.com
Mon Nov 6 07:41:25 PST 2000


Hi,

I am trying to integrate JDOM into one of my projects. I receive a String via a method which I
need to parse and pull data out of. so far I have managed to get the following to work:

        SAXBuilder builder=new SAXBuilder();
        StringBufferInputStream sr=new StringBufferInputStream(getRawDocument());
        try{
          Document doc=builder.build(sr);
          setXMLDocument(doc);
            }
        catch(JDOMException e){}

I then try to get elements of the document via:

public String[] getElementValue (String strElementName) {
       String[] defaultValue =  {"ERROR", "Element not found"};
       Element root=getXMLDocument().getRootElement();
       List values=root.getChildren(strElementName);

       Iterator i=values.iterator();
       Vector v=new Vector();
       while (i.hasNext() )
        {
        Element e=(Element)i.next();
        System.out.println(e.getTextTrim());
        v.add(e.getTextTrim());
        }

       String[] out=(String[])(v.toArray(new String[0]));

       return  out;
    }           //getElementValue

I can pass an array of values back as long as the element I am looking for is directly below the
root element. It will not work if that element is anywhere else. I need a means to pass an element
to find and find it anywhere within the document and then pass the values back. 

Any help is highly appreciated.

Alex



=====
Regards

Alex Colic, HBA, B. Ed
PopWare Inc. "Driving down the cost of conversions"
E-Mail: Alex.Colic at pop-ware.com
Tel: 1-905-777-8171 ext. 104
Fax: 1-905-777-0132

__________________________________________________
Do You Yahoo!?
Thousands of Stores.  Millions of Products.  All in one Place.
http://shopping.yahoo.com/



More information about the jdom-interest mailing list