falcong / pugixml

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

fluent interface would be helpful #48

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Now I have to do it like this:

for (…) {
  pugi::xml_node node = xml.append_child();
  node.set_name("job");
  node.append_attribute("id") = someValue;
  node.append_attribute("type") = "manager";
}

Would be much better if we can use a "fluent interface":

for (…) {
  xml.append_child()
    .set_name("job")
    .append_attribute("id", someValue)
    .append_attribute("type", "manager");
}

This mechanism looks more object-oriented. Maybe it's possible to introduce 
some additional 
methods for such a mechanism? Returning BOOLEAN as a result of function 
execution is rather 
old and C-like style, as I understand. Maybe it's necessary to have existing 
functions in place, 
but the mechanism explained above would be very helpful. Thanks.

Original issue reported on code.google.com by yegor256 on 4 Apr 2010 at 2:17

GoogleCodeExporter commented 9 years ago
Yes, the current interface does not let you chain calls freely. Some additional 
accessors with support for call chaining would be useful; the request is noted. 
I'll 
update this issue once there is further information.

Original comment by arseny.k...@gmail.com on 27 May 2010 at 4:20

GoogleCodeExporter commented 9 years ago
The new version of pugixml, 1.0, lets you use the new append_child function to 
omit the set_name call:

xml_node job = xml.append_child("job");

Making append_attribute return xml_node to support chaining can't be done, 
since the function should logically return the attribute; making an extra 
append_attribute variant just for this case unnecessary complicates the API - 
so there are not going to be any changes to attribute appending.

I'm closing this issue.

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