XML version and encoding from boost ptree

白昼怎懂夜的黑 提交于 2019-12-08 08:56:11

问题


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?


回答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



来源:https://stackoverflow.com/questions/37188774/xml-version-and-encoding-from-boost-ptree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!