I am parsing an XML file using boost property tree of the following type:
<DocName>
<InitCommands>
<OptionalCommands>
<command name="write" address="0x00000000"/>
<command name="write" address="0x00000000"/>
<command name="write" address="0x00000000"/>
</OptionalCommands>
<command name="write" address="0x00000000"/>
<command name="write" address="0x00000000"/>
</InitCommands>
</DocName>
I would like to check if a certain element exists in the XML tree. Below is the code I am using:
namespace pt = boost::property_tree;
int main (){
pt::ptree prop_tree;
read_xml ("my.xml", prop_tree);
pt::ptree::const_assoc_iterator it;
it = prop_tree.find("DocName.InitCommands.OptionalCommands");
if (it != prop_tree.not_found())
std::cout <<"Optional Options found !" << std::endl;
}
However, running this code returns
it == prop_tree.not_found()
This works if I try to find the root element of my xml file i.e
it = prop_tree.find("DocName");
Can someone please suggest how this find() function should be used ?