Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Need to preserver duplicate namespace declarations

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <whoschek AT lbl.gov>
  • To: "Aust, Stefan" <stefan.aust AT coremedia.com>
  • Cc: Elliotte Harold <elharo AT metalab.unc.edu>, xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] Need to preserver duplicate namespace declarations
  • Date: Tue, 9 Aug 2005 09:57:34 -0700


Actually, I perfectly understand that you don't want to implement this
just for me but I'd greatly appreciate any hints how to best modify the
sources to minimize the impact.

My idea was to modify Element#addNamespaceDeclaration() to remember the
fact that is was an explicit addition. It looks like that method is only
called twice in XOMHandler and twice in NonVerifyingHandler (ignoring
DOMConverter and XSLTHandler). Now Element should get a new List of
declared prefixes. Then, I could ask an element whether the namespace
was declared here on in some parent element. Hopefully, that should do
the trick.



Perhaps it might work for you to add this to Element.java:

private static final String[] EMPTY = new String[0];

/**
* Returns a list of (prefix, URI) pairs in the form prefix0, ns0, ...,
* prefixN, nsN, or an empty array if there are no additional namespace
* declarations on this element.
*/
public final String[] getAdditionalNamespaceDeclarations() { // WH
if (namespaces == null) return EMPTY;
ArrayList prefixes = namespaces.getPrefixes();
int size = prefixes.size();
if (size == 0) return EMPTY;
String[] results = new String[2 * size];
for (int i=0, j=0; i < size; i++, j += 2) {
results[j+0] = (String) prefixes.get(i);
results[j+1] = namespaces.getURI(results[j]);
}
return results;
}

I'm considering to use this myself for some special namespace iterations in bnux.
(No, it can't be done with the existing API, at least not in an efficient manner)

Wolfgang.




Archive powered by MHonArc 2.6.24.

Top of Page