Search code examples
c++boostboost-propertytree

XML version and encoding from boost ptree


I am using boost ptree to parse xml

read_xml(stream, pt, trim_whitespace | no_comments);



<?xml version="1.0" encoding="windows-1252"?>
<rss>  
<channel>.....</channel> 
</rss>

How to read the version and encoding of the xml : I tried the following

std::string encoding =  pt.get<std::string>("<xmlattr>.encoding", "");

which gives empty string. How to get the version and encoding of xml?


Solution

  • The processing instruction is not an XML element (in fact, it's... a processing instruction).

    Processing instructions do not have attributes in the <xmlattr> sense. You will note that there is no ptree node corresponding to it.

    Here's an undocumented way to achieve what you likely want: Add xml-stylesheet processing instructions to boost property_tree