[Phoenix] Implementing support for XML documents with unprefixed default namespaces

Andreas Wuest awuest at student.ethz.ch
Fri Sep 22 18:08:39 CEST 2006


Hi

After some consideration, I came to the conclusion that the only way to 
implement this is to patch up an intermediate copy of the XML document 
source to only contain prefixed elements. This would be done before the 
sourcetagger is applied.

The second approach discussed was to use a custom namespace resolver, 
which resolves default (i.e. null) prefixes. This does not work for two 
reasons:

  1. Location path lookup would still result in paths like "/foo/bar". 
Now, if those two elements live in the same default namespace, there is 
no problem. But consider a document like

<foo xmlns="foo.org">
   <bar xmlns="bar.org"/>
</foo>

Our namespace resolver would get two requests for the null namespace 
(one for <foo>, one for <bar>). There is no way for the namespace 
resolver to determine which of the default namespaces is requested 
(because the only parameter which is passed to a namespace resolver by 
the evaluate() method is the prefix (as a string)).

  2. We can't issue an XPath expression as "/ns1:foo/ns2:bar" because 
the only information we would get from the location path is "/foo/bar" 
(because the location path is built using the prefixes (or, in our case, 
no prefixes) from the XML source). There is no way for us to determine 
in which namespace each element lives at the point where we actually 
have to evaluate the expression.

Therefore, I will take the following route:

  1. Retrieve DOM representation of XML source.
  2. Fix it up to only contain prefixed elements.
  3. Apply source tagger.

The only drawback to this approach is that the XPath toolbar will 
display location paths with strange prefixes (i.e, our generated 
prefixes). The user might get confused by those because he can't see 
them in the actual source.

-- 
Kind regards,
Andi



More information about the Phoenix mailing list