Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Namespaces and attributes

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Mik Lernout <mik AT futurestreet.org>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] Namespaces and attributes
  • Date: Tue, 25 Nov 2003 23:22:05 +0100

Hi all,

I have just begun the switch from javax-SAXto XOM and found it suprisingly pleasent.
But I have one rather big problem. When parsing an XML the attributes I get from the XML tree do not have any namespaceURI's attached, for example:

import java.io.IOException;
import java.io.StringReader;

import nu.xom.Builder;
import nu.xom.Document;
import nu.xom.Element;
import nu.xom.ParsingException;
import nu.xom.ValidityException;

public class XOMDemo {

public static void main(String[] args) {
String xmlAsString = "<test xmlns:test=\"http://test.org/Test\";><a test:attribute=\"attributeValue\"></a></test>";
Builder parser = new Builder();
Document doc = null;
try{
doc = parser.build(new StringReader(xmlAsString));
Element aElement = doc.getRootElement().getFirstChildElement("a");
System.out.println("Found attribute value of: " + aElement.getAttributeValue("http://test.org/Test","attribute";));
} catch (ValidityException ex){
ex.printStackTrace();
} catch (ParsingException ex){
ex.printStackTrace();
} catch (IOException ex){
ex.printStackTrace();
}
}
}

returns "Found attribute value of: null"... I don't think this is correct behaviour is it?

Mik

PS: I am using the JDK 1.4.2 and have tried it also with Xerces 2.2.1 with no better results...





Archive powered by MHonArc 2.6.24.

Top of Page