<?xml version="1.0" encoding="ISO-8859-1"?><XArC version="2.0" service="GetHitList" type= "response"><folder name='Vermoegensstatus'><document><docid>100000</docid><metainfo name ='Datum' value ='05.06.2000'></metainfo><metainfo name ='Format' value ='CIB_XML'></metainfo><metainfo name ='Kontonr' value ='2003617103'></metainfo><metainfo name ='Persnr' value ='95897543'></metainfo><appinfo name ='accessed' value =''></appinfo><appinfo name ='archived' value =''></appinfo></document><document><docid>100009</docid><metainfo name ='Datum' value ='05.06.2000'></metainfo><metainfo name ='Format' value ='CIB_XML'></metainfo><metainfo name ='Kontonr' value =''></metainfo><metainfo name ='Persnr' value ='95897543'></metainfo><appinfo name ='accessed' value =''></appinfo><appinfo name ='archived' value =''></appinfo></document><document><docid>100015</docid><metainfo name ='Datum' value ='05.06.2000'></metainfo><metainfo name ='Format' value ='CIB_XML'></metainfo><metainfo name ='Kontonr' value ='2003617103'></metainfo><metainfo name ='Persnr' value ='95897543'></metainfo><appinfo name ='accessed' value =''></appinfo><appinfo name ='archived' value =''></appinfo></document></folder></XArC>
This is the program im using to get the value of child ("docid") from my xml but its giving me a null value someone help me how to do it ..pls
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import java.util.*;
/**
* <p><code>WarReader</code> demonstrates how to
* read a
Servlet 2.2 Web Archive file with JDOM.
* </p>
*
* @author Brett McLaughlin, Jason Hunter
* @version 1.0
*/
public class WarReader {
/** Default SAX Driver class to use */
private static final
String DEFAULT_SAX_DRIVER_CLASS =
"org.apache.xerces.parsers.SAXParser";
/** SAX Driver Class to use */
private String saxDriverClass;
/** <code>{@link SAXBuilder}</code> instance to use */
private SAXBuilder builder;
public static String filename ="D:/web.xml";
/**
* <p>
* This will create an instance of <code>{@link SAXBuilder}</code>
* for use in the rest of this program.
* </p>
*
* @param saxDriverClass <code>String</code> name of driver class to use.
*/
public WarReader(String saxDriverClass) {
this.saxDriverClass = saxDriverClass;
builder = new SAXBuilder(saxDriverClass);
}
/**
* <p>
* This will parse the specified WAR using SAX and the
* SAX driver class specified in the constructor.
* </p>
*
* @param filename <code>String</code> name of file to parse.
* @param out <code>OutputStream</code> to output to.
*/
public void read(String request, PrintStream out)
throws IOException, JDOMException {
// Build the JDOM Document
Document
doc = builder.build(new File(filename));
// Get the root element
Element root = doc.getRootElement();
System.out.println(root.getChildren());
List document = root.getChildren();
System.out.println(document);
List docu = root.getAttributes();
System.out.println(docu);
List servlets = root.getChildren("document");
System.out.println(servlets);
//String text = docid.getText();
//System.out.println(docid);
Element XArC = doc.getRootElement();
System.out.println(XArC);
}
public static void main(String[] args) {
PrintStream out = System.out;
if (args.length != 1 && args.length != 2) {
out.println("Usage: org.jdom.examples.servlet.WarReader [web.xml]");
return;
}
// Load filename and SAX driver class
String filename = args[0];
String saxDriverClass = DEFAULT_SAX_DRIVER_CLASS;
if (args.length == 2) {
saxDriverClass = args[1];
}
// Create an instance of the tester and
test try {
WarReader reader = new WarReader(saxDriverClass);
reader.read(filename, System.out);
} catch (JDOMException e) {
if (e.getRootCause() != null) {
e.getRootCause().printStackTrace();
} else {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}