Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Scope of namespaces

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: peter murray-rust <pm286 AT cam.ac.uk>
  • To: Elliotte Harold <elharo AT metalab.unc.edu>
  • Cc: xom-interest <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] Scope of namespaces
  • Date: Sun, 05 Feb 2006 23:44:43 +0000

At 18:25 05/02/2006, Elliotte Harold wrote:
XOM's about as consistent on this as it's possible to be given the general mess that is namespaces.

I agree that namespaces are one of the worst specs to come out of the process. They were done in a great rush and generated much friction. The use of "http://..."; as a name rather than an address is probably one of the worst ever decisions.

Given any element if you ask for the URI mapped to a given prefix, then it will return the URI as specified by Namespaces in XML.

Agreed. But if I want to ask for the namespaceURIs in scope, rather than the prefixes then I don't seem to be able to get them all:


If you think you've identified a case where this isn't true, then please send in a sample that shows what XOM does report as the namespace URI and what you think it should report instead.

Running under Xom1.12/Junit/Eclipse/Java 5.0:

public void testNamespaceScope() {
String s = "<a xmlns:ns='http://foo'><b foo='ns:bar'/></a>";
Document doc = null;
try {doc = new Builder().build(new StringReader(s));} catch (Exception e) {}
Element a = doc.getRootElement();
System.out.println("NS: "+a.getNamespaceURI("ns"));
Element b = a.getFirstChildElement("b");
int nsCount = b.getNamespaceDeclarationCount();
System.out.println("NSCOUNT: "+nsCount);
for (int i = 0; i < nsCount; i++) {
System.out.println("NSPREFIX"+i+" ["+b.getNamespacePrefix(i)+"]");
System.out.println("NSURI"+i+" ["+b.getNamespaceURI(b.getNamespacePrefix(i))+"]");
}
System.out.println("NS1: "+b.getNamespaceURI("ns"));
}
gives:
NS: http://foo
NSCOUNT: 1
NSPREFIX0 []
NSURI0 []
NS1: http://foo

It seems that the prefix "ns" is not in scope as evidenced by the namespace declaration count and there is no other means of iterating through the namespaces (which is what I sometimes wish to do as I want to see if a namespaceURI is in scope at that stage and I may not know its prefix).

Thanks

P.


Peter Murray-Rust
Unilever Centre for Molecular Sciences Informatics
University of Cambridge,
Lensfield Road, Cambridge CB2 1EW, UK
+44-1223-763069




Archive powered by MHonArc 2.6.24.

Top of Page