> This is obviously a bigger issue than simply querying within Xindice, as > it has more to do with XML Namespaces and default attributes. Generally > when you do a query absent any care over XML Namespace, you already know > the namespace. Because 'xmlns' is merely from the XML 1.0 POV a default > attribute, you wouldn't necessarily want all the defaulted attributes to > be present on a query result (e.g., some HTML elements have quite a > few). 'xmlns' is a *bit* different than other attributes and I wouldn't > be surprised to see implementations vary in their handling of it.
I think for the majority of cases it would be a matter of the engine being able to record the namespace declarations "in play" at the target element. These namespace declarations would need to be added to the result node. Additions and changes in namespace declarations on child elements would take care of themselves. This wont always work for documents validated with a DTD, as the namespace declaration could well be within an external external entity decalred in a dtd. I believe there is a better solution though. At the moment a query result is converted to a string when the result XMLResource is created. If the node was stored stored as a node the the namespace information may not be lost. I'm looking at the code today to see if this is a workable solution. > I'm not sure I'd consider that the 'xmlns' was "lost", as it's not (as > above) really a normal attribute. By extension, if you queried and > returned a large XML document, you'd not want 'xmlns' attributes on > *all* the returned elements (I wouldn't think). I agree, that you don't want all the element nodes to have all the possible namespace declarations. > The real answer to this problem is probably fairly elusive as handling > of 'xmlns' has historically been pretty murky. > > You might try this with explicit prefixes and a short DTD to see if you > get the results you want. My work around is to standardize the prefixes used in documents. I have a small patch that adds the namespaces used in the query to the result node (if it's an element). This works in my case, but is not a real solution. This is the reason I haven't submitted it as a patch. I think something along the lines I have set out above though may be possible. > Again, I'd try this with a short DTD and explicit attributes to see if > your results improve, say, something like: > > <!DOCTYPE n:a [ > <!ELEMENT n:a ( n:b )* > > <!ATTLIST n:a > xmlns:n CDATA #FIXED "http://example.com/" > > > <!ELEMENT n:b ( PCDATA )* > > <!ATTLIST n:b > xmlns:n CDATA #FIXED "http://example.com/" > > > ]> > <n:a xmlns:n="http://example.com/"> > <n:b xmlns:n="http://example.com/">foo</n:b> > </n:a> > > Unfortunatly having a DTD decarled doesn't help, as the result node has no idea that the DTD even exists :(. Thanks for your thoughts though :). I'm sure this is solvable with a little thought and a bit of coding. The xindice code is so easy to work with in the majority of cases. -k.