Bjoern Hoehrmann wrote:
Which you can, with a non-NS-aware XML parser.
My point was that the XHR draft currently requires using a namespace-
aware one
On the server side? Can you point me to where it makes that requirement?
I'm not suggesting that the parser XHR uses for data it receives from the server
be changed; I'm suggesting that the server should be able to use whatever XML
parser it wishes.
The problem is that figuring out whether a DOM fragment can usefully
be serialized as a ns-wellformed string is a bit of a pain.
Could you elaborate on this point? You need to serialize the document
before starting to send it
Agreed.
and you can rather easily check for ns-wf during serialization if you implement
the serialization yourself
Perhaps. This is less clear to me. In particular, it's not that clear to me
that its trivial to decide whether a given DOM has a ns-wellformed
serialization. Certainly there have been a number of past bugs in the Gecko
serializer dealing with this aspect of things, and I wouldn't bet my life on
there not being any now.
Even if you cannot do it during serialization, the algorithm to do it on the
document object is relatively simple aswell.
The concept of "namespace well-formed" applies to strings, not document objects,
last I checked. Though Firefox does prevent creation of attribute nodes with
the prefix "xmlns" in random namespaces, so maybe I'm wrong about that.
In any case, let me give an example, as requested.
var doc = document.implementation.createDocument("", "", null);
var el = doc.createElementNS("ns1", "x:y");
el.setAttributeNS("ns2", "x:z", "val");
doc.appendChild(el);
var xhr = new XMLHttpRequest();
xhr.open("POST", "echo.cgi", false);
xhr.send(doc);
alert(xhr.responseText);
Here echo.cgi is the following CGI:
#!/usr/bin/perl
print "Content-Type: text/plain\n\n";
while (<>) {
print;
}
Here are the results I see:
Firefox 3rc1:
<x:y xmlns:x="ns1" a0:z="val" xmlns:a0="ns2"/>
Opera 9.25:
<?xml version="1.0"?><x:y x:z="val" xmlns:x="ns1"/>
Safari 3.1:
<x:y x:z="val" />
Ignoring the Safari serialization, which is not in fact ns-wellformed no matter
how you slice it, the other two are ns-wellformed XML. Neither one roundtrips
to quite the original document. Which one is "correct" per the current spec?
Or is it neither one? Should an exception have been thrown in this case? Why
or why not? If there shouldn't have been an exception in this case, how is a UA
to determine that?
I'm not saying these are impossible things to define; just that they're far from
obvious (as witness the three serializations above) and therefore perhaps need
definition in this spec if we want interoperability.
-Boris