falcong / pugixml

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

Extension to find_child_by_attribute functionality #131

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What feature do you require in pugixml?
I need to be able to retrieve to the next sibling that matches a name and 
iteration. find_child_by_attribute behavior but going onwards from the first 
node returned.

What do you need this feature for?
It would enable finding nodes that share name/attribute but are not contigious.

If you already have a patch, please attach it to the issue.

Original issue reported on code.google.com by calvin.c...@gmail.com on 11 Oct 2011 at 9:18

Attachments:

GoogleCodeExporter commented 9 years ago
"iteration" is meant to be attribute.

Original comment by calvin.c...@gmail.com on 12 Oct 2011 at 2:52

GoogleCodeExporter commented 9 years ago
find_child_by_attribute functions were not intended for iteration. Achieving 
iteration can be done by using attribute() with (arguably) simpler code, i.e.

for (pugi::xml_node child = node.find_child_by_attribute("item", "type", 
"text"); child; child = child.next_sibling_by_attribute("item", "type", "text"))
{ ... }

vs

for (pugi::xml_node child = node.child("item"); child; child = 
child.next_sibling("item"))
    if (strcmp(child.attribute("type").value(), "text") == 0)
    { ... }

Note that the attribute text/value is not duplicated in the second example, 
making it potentially less error prone.

find_child_by_attribute usage for finding makes the code shorter and more 
readable (without it you'd need an explicit loop) - for iteration it does not 
make much sense.

It is possible to make a new iteration functionality to make this code simpler, 
but it does not occur frequent enough; adding next_sibling variants will 
therefore unnecessarily clutter the interface.

I'd suggest changing the code to explicitly check the attribute value, or, if 
you're convinced that next_sibling variants are useful, add them to your own 
header as free functions to keep pugixml unmodified.

Original comment by arseny.k...@gmail.com on 3 Apr 2012 at 2:06