2

Trying to get the content from the xml file using boost xml parser using c++..

opencv.xml

<opencv_storage>
     <labels type_id="opencv-matrix">
          <data>0 0 0 0 1 1 0 0</data>
     </labels>
</opencv_storage>

C++ Code Snippet

using boost::property_tree::ptree;
    ptree pt;
    boost::property_tree::read_xml("opencv.xml", pt);

    std::string m_file = pt.get<std::string>("opencv_storage.labels type_id=\"opencv-matrix\".data");

    std::cout<<"m_file "<<m_file<<std::endl;

While executing, the program throws an exception :

No such node (opencv_storage.labels type_id="opencv-matrix".data)

I doubt, a white space prevails between labels and type_id

Thanks in advance, any help would be appreciated, since I am trying to get used to boost.

Amarnath R
  • 973
  • 3
  • 14
  • 33

1 Answers1

1

Of course it doesn't. Whitespace in element names is illegal in XML.

What you actually want is attributes: Parsing XML Attributes with Boost

Or, better yet, you want to use an XML parser, here: What XML parser should I use in C++?


If somehow you want to use poperty tree (are you sure?) look here:

The enumerate-path function can - obviously - be used for XML too, since it takes a ptree

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633