[xml] Namespace handling for attributes when there's no namespace qualifier

If I understand the namespace recommendation correctly, an attribute whose name is not qualified with a namespace is assumed to be in the same namespace as the element to which the attribute belongs.

If I create an element foo in the namespace bar which has an empty string for its prefix, and make an attribute on that element, also in the namespace bar, then the attribute gets written without a qualifier (which seems right) - that is, as

<foo xmlns="some-uri-to-bar" attr="whatever" />

Now, if I read this back in with, say, xmlParseFile, the attribute named attr has a namespace of NULL, and not the same namespace as foo.

Similarly, if I have a file that reads
<bar:foo xmlns="some-uri-to-bar" attr="whatever" />

...then the attribute is also not in the bar namespace.

I would provide a patch, but I'm only just getting familiar with the source code and I'm not sure if the best place to fix this is in my_attribute() of SAX.c, which passes NULL to xmlNewNsPropEatName() in this case, or if xmlNewNsPropEatName() (and the other property functions as appropriate) should be modified to handle the NULL namespace case by setting the namespace to the same as that of the node.

To further complicate issues, if we do either one of these, then the data model for

<foo:element foo:attribute="1" />

is identical to the data model for

<foo:element attribute="1" />

I can imagine this being a problem if a coder decides to replace the namespaces in an element, because in the first case you might not want to change the attribute namespace since it was explicity set, and the second you might because it is implied that it follows the element. OTOH, I can also imagine just telling programmers they have to live with it.

Suggestions?  Or am I barking up the wrong tree entirely?


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]