falcong / pugixml

Automatically exported from code.google.com/p/pugixml
0 stars 0 forks source link

Need "document element" functionality. #71

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Every XML document has one element that is the root of all others. Interpreting 
an XML document usually begins at this "document element". The W3C DOM 
consequently has a document.getDocumentElement() method.

pugixml has no such method, forcing the developer for every XML document to 
iterate through all children of the document trying to find the document 
element.

Original issue reported on code.google.com by garretdw...@gmail.com on 13 Aug 2010 at 5:49

GoogleCodeExporter commented 9 years ago
Sorry for the delay.

In case you know the element name (which is true for the majority of use 
cases), you can use child() method. Please, describe the particular use case 
you have in mind; if it is a relatively common one, I'll add the corresponding 
function.

Original comment by arseny.k...@gmail.com on 19 Aug 2010 at 11:43

GoogleCodeExporter commented 9 years ago
* What if you have a XML format that can have one of various document elements 
(e.g. <image> or <audio>?) Why force the developer to do multiple searches when 
they could simply 1) get the document element and then 2) compare the name?

* What if you use XML as an ad-hoc serialization of some class instance graph 
in memory (everybody is doing this nowadays, from Java to C#)? You may have no 
idea what the root element name will be---you just want to say, "give me the 
root element."

* Getting the root element now is made even more complicated because XML 
documents can have several types of notes that are children of the document. 
Why should we have to iterate them all and check the type of each one?

The "document element" is formally part of the XML specification. Why not 
provide API access to it as such?

http://www.w3.org/TR/xml/
http://www.w3.org/TR/xml-infoset/

Thanks,

Garret

Original comment by garretdw...@gmail.com on 7 Oct 2010 at 4:28

GoogleCodeExporter commented 9 years ago
The xml_document::document_element function was added to the trunk; the next 
version, which is released in two weeks, will have it.

Original comment by arseny.k...@gmail.com on 18 Oct 2010 at 6:28

GoogleCodeExporter commented 9 years ago
pugixml-1.0 is out; it has the document_element function.

Original comment by arseny.k...@gmail.com on 31 Oct 2010 at 6:20