-3

I have a question regarding the extraction of parameter values from an xml file using pugixml. I have an XML file with a hierarchical structure, and would like to retrieve the value associated with a specific parameter.

Part of the file looks like this:

<Path>
  <HardParameters>
   </HardParameters>
  <AdjustableParameters>
    <Parameter name="Path Bandwidth" units="rad/s">
      <symbol>wC</symbol>
      <description>Closed loop BW</description>
      <value>3.9</value>
      <reference>IEEE</reference>
     </Parameter>
     <Parameter name="Foo" units="">
      <symbol>zeta</symbol>
      <description>Foo ratio </description>
      <value>4.1</value>
      <reference>IEEE</reference>
     </Parameter>
  </AdjustableParameters>
</Path>

For instance, I would like to retrieve the value 4.1 of the Foo ratio. I wonder if the function

xpath_variable* get( const char_t* name );

is the one I should use in this case? And how should it be used in such case? Just pass the name of the parameter as an argument?

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
Wballer3
  • 141
  • 1
  • 9

1 Answers1

1

Yes you can use an XPath of //Parameter[@name = 'Foo']/value/text() to get the text of the value element inside a parameter with an attribute name with value Foo:

xml_node root
xpath_node value = root.select_node("//Parameter[@name = 'Foo']/value/text()");
Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
  • Thank you for your answer! Just one more question, how can I extract the data as a double from 'value'? I saw an examlpe where the following happens: double timeout = tool.attribute("Timeout").as_double(); I want to do a similar operation, but 'value' now does not have an attribute, right? Or is 4.1 regarded as an attribute? – Wballer3 Aug 21 '18 at 12:32
  • I believe I found the answer: double paramValue = value.text().as_double(); is the way to go, I guess? – Wballer3 Aug 21 '18 at 12:37
  • Your approach does not seem to work - I looks like value has to be of type xpath_node. – Wballer3 Aug 21 '18 at 13:54