falcong / pugixml

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

casting with child_value() #136

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

Lets say I have an xml

<Array>
  <Array index=0> 1 <\Array>
  <Array index=1> 2 <\Array>
  <Array index=2> 3 <\Array>
<\Array>

Then I write something like to get the 2 element

  .select_single_node("Array\Array[@index='1']").node().child_value()

This will return a string instead of an int.
Is there an built in cast I can use with .child_value() like .as_int() can be 
used with .attribute()?

Thanks,  Sam

Original issue reported on code.google.com by samkhali...@hotmail.com on 29 Nov 2011 at 10:39

GoogleCodeExporter commented 9 years ago
No, there is not; you can use the 'atoi' function from stdlib. child_value() 
never returns null pointer, so just doing atoi(n.select[...].child_value()) 
will be safe (zero if selection fails).

Original comment by arseny.k...@gmail.com on 29 Nov 2011 at 4:04

GoogleCodeExporter commented 9 years ago

Original comment by arseny.k...@gmail.com on 9 Dec 2011 at 5:52