LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-30-2004, 08:51 AM   #1
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Rep: Reputation: 18
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
 
Old 07-01-2004, 08:47 AM   #2
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Original Poster
Rep: Reputation: 18
neone having ne idea whts the problem with my code ??
 
Old 07-01-2004, 11:17 AM   #3
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
checking for XML::Parser... configure: error: XML::Parser perl module is required for kornerr Linux - General 11 11-16-2008 07:24 AM
infomation extraction Dave Kelly Programming 2 10-27-2005 08:56 PM
Extraction error Fcm Linux - Software 1 02-09-2005 05:58 PM
extraction of words pantera Programming 4 10-15-2004 02:28 PM
BTarball Extraction harperonline Linux - General 2 02-05-2004 08:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration