[jdom-interest] newbie help on parsing xml with namespaces

Charlie Wu cwu at brocade.com
Fri Jul 26 13:24:32 PDT 2002

Hi all:

I'm having some trouble xml with namespaces.. my xml file is like the

<?xml version='1.0' encoding='UTF-8' ?>
<AuthLoginResponse version="1.0" xml:lang="en" status="0"

I want to be able to retrieve the SessionID.. I'm adapting the
WarReader.java to do this.. but I noticed that
if I don't indicate the namespace I'm not getting anything.. but how do I
set the namespace? I thought 
"com:abc:developer" should be the prefix but compiler is saying prefix can
not have colons.. I tried breaking
it up so com is the prefix and abc:developer is the uri but I'm getting a
null pointer error when I run this..

        // Build the JDOM Document
        Document doc = builder.build(new File(filename));

        // Get the root element
        Element root = doc.getRootElement();
        Namespace ns = Namespace.getNamespace(prefix_string, uri_string);
<------------ what should be here?

        // Print servlet information
        List servlets = root.getChildren("Control", ns);
        out.println("This WAR has "+ servlets.size() +" registered
        Iterator i = servlets.iterator();
        while (i.hasNext()) {
            Element servlet = (Element) i.next();
            out.print("\t" + servlet.getChild("SessionID").getTextTrim());

can someone help?



More information about the jdom-interest mailing list