Read all nodes in a XML file

449 views Asked by At

I have an XML file which looks like following:

<Employee>  
    <AddressDetails>
        <Street>ABC</Street>
        <City>XYZ</City>
        <Country>KLM</Country>
    </AddressDetails>

    <EmployeeName>LMNOP</EmployeeName>
    <EmployeeID>123456</EmployeeID>

    <FamilyDetails>
        <Status>single</Status>
        <Children>0</Children>
    </FamilyDetails>
</Employee>

I want to read the values of all the nodes and store the node name and its value in two strings. I can read all the nodes under the root node AddressDetails with the following code. But how do I read all the nodes of Employee.

xml_node root_node = doc.child("Employee");
xml_node Address_node = root_node.child(AddressDetails);

    for(xml_node child = Address_node.first_child(); child; child = child.next_sibling())
    {
        std::string NodeName = child.name();
        std:string NodeValue = child.text().as_string();
    }
0

There are 0 answers