I would like to know if Boost Ptree allows parsing .xml files without having the attribute tags known. I have an XML file that will regularly be updated with new tags, new data, and even remove certain tags. These regular changes prompted me to look into parsing the file without hardcoding the attribute name. Is there any way I can read all the data in the XML file without stating the tag name? Any help is appreciated!
Ptrees aren't ideal for parsing XML but Boost is so integrated into the rest of my project that it would be incredibly taxing to use libxml2 or another parser
Sorry, that makes no sense.
There are header-only options, and a good number of very light-weight options. See What XML parser should I use in C++?
Since Boost Property Tree is simply and clearly not the library you need the perceived cost of adding a library will be far outweighed by the cost of battling the broken abstractions and impossibilities that you will encounter.
And it seems like I do have to state the tag name when I use read_xml. There doesn't seem to be a way that I can read all the child nodes underneath a parent node and store them.
Here you go:
#include <boost/property_tree/xml_parser.hpp>
int main() {
boost::property_tree::ptree pt;
std::ifstream ifs("input.xml");
read_xml(ifs, pt);
write_xml(std::cout, pt);
}
I've also read through the boost documentation but couldn't seem to find anything.
I'd start here: https://www.boost.org/doc/libs/1_73_0/doc/html/property_tree/parsers.html#property_tree.parsers.xml_parser. Focus on the limitations. Not all limitations are explicit there (see documentation for RadidXML).
Do you know how boost get child nodes or other c++ parsers I could look at?
See first link above :)
See also: