LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   xml extraction using JDOM (https://www.linuxquestions.org/questions/programming-9/xml-extraction-using-jdom-199465/)

linux_ub 06-30-2004 08:51 AM

xml extraction using JDOM
 
hey guys

i have an xml file which looks something like this

Code:

<LMR>
<REPORT ID="1">
    <DATE>2004-3-19</DATE>
    <CLAIMANT>ABC DEF</CLAIMANT>
    <AGE>35</AGE> ......

the attribute "ID" of the tag REPORT gives me the nth record in the xml file. my requirement is to extract the nth record where n is supplied by a query to a mysql database. i have written the following code using JDOM but am unable to compare the attribute value .... ne ideas where i am going wrong ...

Code:

import java.io.IOException;
import java.util.List;

import org.jdom.*;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;


public class readXML {

        public static void main(String[] args) throws JDOMException, IOException {
                SAXBuilder builder = new SAXBuilder();
                Document document = builder.build("d:/report.xml");
                Document doc = new Document();
                Element root = document.getRootElement();
                Element ele = new Element ("OUTPUT");
                //doc.setRootElement(ele);
                List someChild = root.getChildren("REPORT");
                System.out.println(someChild.size());
               
                for (int i=0;i<someChild.size(); i++) {
                        Element temp = (Element) someChild.get(i);
                        String s = temp.getAttributeValue("ID");
                       
                        //Attribute a = temp.getAttributeValue();
                        if (s.trim() == "5") {
                                List children = temp.getChildren();
                        }
                }

        }
}

i cannot get a list of the children of [REPORT ID="5"] .... the if condition is never satisfied

thanks

linux_ub 07-01-2004 08:47 AM

neone having ne idea whts the problem with my code ??

coolman0stress 07-01-2004 11:17 AM

Why are you using JDOM in the first place? Java comes with great SAX and DOM parsers already (org.w3c.dom, org.xml.sax namespaces). Also, if all you are doing is going through the XML file (without later on modifying it), i'd recommend using SAX instead of DOM as it's a lot faster.


All times are GMT -5. The time now is 06:34 PM.