Re: cannot find the namespace declarations from an extension function
Michael Ludwig <[email protected]>
| Newsgroups | gmane.text.xml.xalan.java.user |
|---|---|
| Message-ID | <[email protected]> |
Adrian Herscu schrieb:
> Michael Ludwig wrote:
>>> Hmmm... It appears that the parser completely ignores all 'xmlns'
>>> attributes. The interesting thing is that it reads attributes from
>>> other non-null namespaces.
>>
>> The xmlns may look like an attribute, but it really isn't. It's a
>> namespace declaration, which happens to use attribute syntax.
> http://www.w3.org/TR/xml-names/#ns-decl
>
> [Definition: A namespace (or more precisely, a namespace binding) is
> declared using a family of reserved attributes. Such an attribute's
> name must either be xmlns or begin xmlns:. ...]
>
> Hence a namespace declaration is an attribute with special meaning,
> but still just an attribute.
Well, I'd say, both are right, depending on which view you take :-)
But on this list the view should probably be Xalan, hence XSLT and the
XPath Data Model. A namespace declaration attribute isn't an attribute
in XDM, because it's not on the attribute axis. The fact that namespace
declaration serialization happens to take attribute form doesn't matter.
>> That's why it doesn't show up among the attributes, neither in DOM
>> nor in XDM (XPath Data Model).
>
> The Xerces DOM parser recognizes xmlns: prefixed attributes as
> attributes. The problem was with the DTM parser used by Xalan.
Here's a small, standalone, and off-topic script in PHP using LibXML2,
where the attributes don't show up. But you're right, using Xerces they
do show up. So I guess DOM (which level?) requires them to show up. Does
anyone know whether and, if so, where the correct behaviour is
specified?
Michael Ludwig
milu@colinux:~/Werkstatt/php > expand -t2 ns-attr.php
<?php
$docstr = '<x:Urmel xmlns="urn:x-U" xmlns:x="urn:x-X" y="3" z="4"/>';
$dom = new DOMDocument;
$dom->loadXML( $docstr);
$elm = $dom->documentElement;
if ( $elm->hasAttributes() ) {
$attlist = $elm->attributes; # DOMNamedNodeMap
for ( $i = 0; $node = $attlist->item($i); $i++ ) {
echo $node->name, "\n";
}
}
milu@colinux:~/Werkstatt/php > php ns-attr.php
y
z