Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Bug in Element.getNamespaceURI(String prefix)

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
  • To: XOM-interest <XOM-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] Bug in Element.getNamespaceURI(String prefix)
  • Date: Fri, 7 Feb 2003 07:22:38 -0500

At 12:25 PM +0100 2/7/03, Laurent Bihanic wrote:
Hi,

It is not possible to retrieve the default namespace URI using getNamespaceURI("") if the current element has at least one attribute not belong to any namespace.

The test case is the following:
<b xmlns="urn:x-xom:b" id="b">
<c:c xmlns:c="urn:x-xom:c" id="c" />
</b>

Invoking getNamespaceURI("") on element "b" returns "urn:x-xom:b" but invoking getNamespaceURI("") on element "c" returns "".

The problem lies in getLocalNamespaceURI() while scanning attribute namespaces. This method should makes a special case for the empty prefix and avoid checking attribute namespaces in this case.

OK, I'll write a unit test for this one, and make sure it gets fixed in this weekend's batch of namespace changes. Thanks for the catch.

Another problem is the way to handle null prefixes. XOM is not consistent here as some methods check against null prefixes and assume "" (Namespaces.remove()) while others (getLocalNamespaceURI()) do not check and throw NullPointerExceptions.


Let me think about this. The question is whether null should always throw the NullPointerException or should always be treated the same as the empty string, right? TRhere may be a problem with the Buolder receiving SAX events that makes this tricky, but I'll need to investigate further.
--

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo AT metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| Processing XML with Java (Addison-Wesley, 2002) |
| http://www.cafeconleche.org/books/xmljava |
| http://www.amazon.com/exec/obidos/ISBN%3D0201771861/cafeaulaitA |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
| Read Cafe con Leche for XML News: http://www.cafeconleche.org/ |
+----------------------------------+---------------------------------+




Archive powered by MHonArc 2.6.24.

Top of Page