
On 06.03.06 15:54:01, Kasimier Buchcik wrote:
On Mon, 2006-03-06 at 14:44 +0100, Andreas Pakulat wrote:
On 06.03.06 14:06:37, Kasimier Buchcik wrote:
The function xmlDOMWrapReconcileNamespaces() does not try to eliminate namespace declarations for different namespace prefixes.
But that's exactly what the libxml bugreport is about.
Then I'm not eager to implement this. But maybe someone else will enhance the function to do what you want.
:-(
This is due to QNames in attribute/element content. QNames need a corresponding ns-prefix to be in scope; thus Libxml2 tries to avoid automatic renaming of prefixes.
Now I'm not too familiar with the specs, but does ":" in element content need escaping? If not, then how can you distinguish a string content containing ":" at some point from a QName as element content, if you don't have an XML Schema at hand that tells you?
This is exactly the problem: the tree modification functions do not know where you intended to use QNames, so currently the only robust way to keep the correct prefix for a QName in scope, is to avoid modifiying prefixes of ns-declarations by QName-in-text-content ignorant mechanisms.
I guess these modification function cannot use a xml schema document that is references by the xml document? If they could, you could say: All element content that is not an element itself is a string, which would be OK with the XML spec, AFAIK. This way you would either know (from the schema) that the content is a QName (or can contain one) or treat it as simple text.
Example:
<x:foo xmlns:x="urn:test:FOO"> <y:bar xmlns:y="urn:test:FOO">y:myQNameValue</y:bar> </x:foo>
For my personal use-case it would be sufficient if the bar element could take the prefix from foo and you leave the extra ns-decl in it so the QName is still in scope.
Hmm, what you describe here is not an elimination of redundant ns-declarations.
Right, as I said this is just my usecase, where a document like <foo xmlns="myuri"> <bar attribute1="blub" /> </foo> is turned into something like the following, if I insert new Elements not using SubElement class, but the Element one: <foo xmlns="myuri"> <bar attribute1="blub" /> <ns0:but xmlns:ns0="myuri">content</ns0:but> </foo> And I'd like to avoid this extra namespace declaration. Also I'm going to add new elements very often and thus the xml document is only machine-readable afterwards, because it's cluttered with namespaces. Andreas -- You will pass away very quickly.