[xml] libxml2 and default namespaces


There was recently a thread on comp.lang.python which touched on the issue of 
serialising documents whose root elements have namespaces associated with 
them, but whose qualified names do not include any prefix. So, by defining a 
root element with namespace URI as "DAV:" and qualified name "href", the 
discussion focused on whether the correct serialisation would be this...

<?xml version='1.0'?>
<href xmlns='DAV:'/>

...or this...

<?xml version='1.0'?>

Here's a link to that thread:


Whilst the complaint was originally directed at Python's minidom, which 
currently serialises the document in the latter fashion for some parts of 
that API and in the former fashion for other parts, libxml2's behaviour was 
also discussed in the context of a DOM-style wrapper that I've written, which 
is known as libxml2dom. Here's a link to that library:


In that library, I access the libxml2mod API exposed by the Python bindings to 
libxml2, and it appeared that either I've been using that API incorrectly, or 
that libxml2 interprets the various standards in a particular way that some 
(justifably or otherwise) disagree with. To create a document as described 
above, I perform the following calls:

document = libxml2mod.xmlNewDoc(None)
element = libxml2mod.xmlNewChild(document, None, "href", None)
ns = libxml2mod.xmlNewNs(element, "DAV:", None)

The serialised result is that given first above (with the xmlns attribute 
present). I suppose my question is this: am I using the API correctly by 
creating a new namespace, or should I be more conservative in creating 
namespace objects? Personally, I don't see anything outrageously wrong with 
the resulting serialisation, but I know that many people have studied the 
standards in much more depth than I have.

Does anyone have a strong opinion about this matter? Who is right and who is 
wrong? What have I done wrong? ;-)


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