1

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?

Chris Schmich
  • 28,454
  • 5
  • 73
  • 94
Hummingbird
  • 627
  • 7
  • 24

1 Answers1

1

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

Community
  • 1
  • 1
sehe
  • 350,152
  • 45
  • 431
  • 590
  • Thanks @sehe, but i think xml_writer_setting always return **utf-8** as encoding [boost xml witer](http://www.boost.org/doc/libs/master/boost/property_tree/detail/xml_parser_writer_settings.hpp), doesn't it? – Hummingbird May 13 '16 at 01:32
  • 1
    Basically, what you're discovering is that Boost doesn't have an XML library. – sehe May 13 '16 at 01:35