Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] why set the namespace again?

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: "Steve Loughran" <steve.loughran AT gmail.com>
  • To: xom-interest <xom-interest AT lists.ibiblio.org>
  • Subject: [XOM-interest] why set the namespace again?
  • Date: Tue, 6 Jun 2006 14:59:22 +0100

Looking at the tail end of Element.addNamespaceDeclaration() I see this

String currentBinding = getLocalNamespaceURI(prefix);
if (currentBinding != null && !currentBinding.equals(uri)) {

String message;
if (prefix.equals("")) {
message = "Additional namespace " + uri
+ " conflicts with existing default namespace "
+ currentBinding;
}
else {
message = "Additional namespace " + uri
+ " for the prefix " + prefix
+ " conflicts with existing namespace binding "
+ currentBinding;
}
throw new NamespaceConflictException(message);
}

if (namespaces == null) namespaces = new Namespaces();
namespaces.put(prefix, uri);

It seems to me that if currentbinding!=null &&
currentBinding.equals(uri), there's no need to bother with the put()
operation again.which saves on a few operations whose O() will be
relatively low order, but still somewhat gratuitous:

void put(String prefix, String URI) {
namespaces.put(prefix, URI);
prefixes.remove(prefix);
prefixes.add(prefix);
}

Is the assumtion here that because getLocalNamespaceURI(prefix); also
scans the attributes for xmlns declarations, the act of adding the
namespace moves the prefix,namespace declaration into the hash table,
so speeding up later operations?

Steve




Archive powered by MHonArc 2.6.24.

Top of Page