[Expat-discuss] XML_ParserCreateNS

Karl Waclawek karl at waclawek.net
Tue Dec 14 02:18:06 CET 2004



Peter Van der Beken wrote:
> Quick question about XML_ParserCreateNS, expat.h has this as description:
> 
> /* Constructs a new parser and namespace processor.  Element type
>    names and attribute names that belong to a namespace will be
>    expanded; unprefixed attribute names are never expanded; unprefixed
>    element type names are expanded only if there is a default
>    namespace. The expanded name is the concatenation of the namespace
>    URI, the namespace separator character, and the local part of the
>    name.  If the namespace separator is '\0' then the namespace URI
>    and the local part will be concatenated without any separator.
>    When a namespace is not declared, the name and prefix will be
>    passed through without expansion.
> */
> 
> The last sentence confuses me, is that only in the case of the namespace 
> separator being '\0'? I definitely got XML_ERROR_UNBOUND_PREFIX for an 
> undeclared prefix and I don't see where that's special-cased for '\0'.

About '\0' as namespace separator:

Good observation. I looked in xmlparse.c for all occurrences
of namespaceSeparator, and found a somewhat confusing picture.

It seems that at some point there was an intention to omit
the separator if it is '\0', but it has not been followed
through consistently, especially not for the element name
in a non-empty tag.

However, later a feature called ns_triplets was added,
which adds the prefix to the end of the name - again
separated with the namespaceSeparator. In my opinion,
having all three concatenated without any spearator makes little
sense.

I am inclined to change the code to simply use whatever
namespace separator is supplied, even if it is '\0'.

Can you think of any use case for having the separator omitted?
Fred, if you read this - do you remember why this feature
was provided?

About the last sentence:

 >    When a namespace is not declared, the name and prefix will be
 >    passed through without expansion.

This makes no sense to me either - when namespace processing is
turned on - as the parser would then not conform to the namespaces
specification, if I remember correctly.

So, I suggest two steps:
- modify namespace separator code as above and adjust comments/docs
- remove the sentence above from the comments/docs


Karl


More information about the Expat-discuss mailing list