SAX2: Namespace Processing and NSUtils helper class

Ray Waldin rwaldin at pacbell.net
Thu Dec 16 10:23:58 GMT 1999


> I assume you mean "p2" instead of "ns2" ?

Yes.  My mistake.

> Slight problem.
> 
> The namespaces are defined *after* the element
> tag begins.  So, startNamespace would logically
> be *inside* of the element like:

I disagree.  I would argue that namespaces are declared before the element start tag ends.
And it is only *after* the start tag ends that a parser can trigger the startElement event
as it must parse the entire start tag to gather all attributes.  So it makes sense to send
startNamespace events before the startElement event for the element in which the namespace
is declared.

> startDocument()
>   startElement(name="element1" attributes="{...}" )
>     defineNamespace(prefix=null, uri="uri1");
>      ...
> 
> However, attributes (since they are random
> and not sequential access), occur within
> the event scope of the element.  Yet, the
> namespace applies to the attribute!

This is an area that's always been a little unclear to me.  Given the following XML:

<a b="c" xmlns="u1">
  <d:e f="g" xmlns:d="u2"/>
</a>

What is the namespace of the f attribute?  From my understanding of the spec, I think it's
"u2", but I'm not sure how that differs from an attribute called d:f on the same element. 
Or is d:f not allowed because it's expanded name is identical to f's expanded name?
 
What's even more confusing is...what about b?  According to the spec, "the default
namespace does not apply to attribute names".  So then everything in the above example
belongs to a namespace except b?  That doesn't make sense...

> I realise you put the events immediately
> preceding the begin tag and immediately
> following the end tag to get around this
> problem, but it just doesn't look pretty.

Yet I think this is what was intended by http://www.w3.org/TR/REC-xml-names#scoping: 

"The namespace declaration is considered to apply to the element where it is specified and
to all elements within the content of that element, unless overridden by another namespace
declaration with the same NSAttName part"

-Ray

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To unsubscribe, mailto:majordomo at ic.ac.uk the following message;
unsubscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)





More information about the Xml-dev mailing list