-3

Having an XML node object (the parent one), how can I retrieve the text value of one of the children nodes in C++?

Jan Hohenheim
  • 3,552
  • 2
  • 17
  • 42
Dave ddd
  • 117
  • 9

1 Answers1

1

First use the method on your parent that gives you the child node you want.
Then use the method on that object that lets you access its text.

If you happen to use RapidXML, which I like to recommend, there's an easy parsing example found here.

The essential part is:


 root_node = doc.first_node("MyBeerJournal.xml");

reads an XML file called MyBeerJournal.xml


for (xml_node<> * brewery_node = root_node->first_node("Brewery"); brewery_node; brewery_node = brewery_node->next_sibling())
{
   ...
}

lets you iterate over the nodes, starting with the one called Brewery.


auto beerName = brewery_node->first_attribute("name")->value();

finally lets you access the text value of the desired attribute, in this case name

Community
  • 1
  • 1
Jan Hohenheim
  • 3,552
  • 2
  • 17
  • 42