Hi,

I have a slightly philosophical question. XML specs says that there can be only 
one root element in a XML document. However, libxml allows you to have any 
number of element children in a document node. Starting from a valid document, 
you can add or remove child elements of the document node freely. You get an 
error when you try to e.g. save such a document.

My view is that it is a "loophole". Single root element is not enforced, 
because you could need in some situations to temporarily  have an empty 
document or a document with multiple root elements. But you should not rely on 
it and try to have a single root element most of the time.

My coworker views it as a "feature" that allows you to e.g. easily merge two 
documents into one (they can have different root elements names). And then use 
XPaths on this merged document in (almost) the same way as you would with the 
two original documents.

What would you say? Why is there this single root element rule anyway?

The reason I am asking is that our software was written in a way that exploits 
this "loophole" (uses this "feature"), but now when extending some 
functionality I get those XML errors. But it is also hard to fix without 
breaking backward compatibility...

Thanks.

Vojtech
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml

Reply via email to