boost ptree的XML版本和编码

XML version and encoding from boost ptree

本文关键字:编码 版本 XML ptree boost      更新时间:2023-10-16

我正在使用boost ptree来解析xml

read_xml(stream, pt, trim_whitespace | no_comments);

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

如何读取xml的版本和编码:我尝试了以下

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

其给出空字符串。如何获取xml的版本和编码?

处理指令不是XML元素(事实上,它是……一条处理指令)。

处理指令不具有<xmlattr>意义上的属性。您会注意到没有与之对应的ptree节点。

这里有一种未记录的方法来实现您可能想要的功能:添加xml样式表处理指令以增强property_tree