如何使用 boost 属性 树提取 xml 文件的 DOCTYPE 节点?

How can I extract an xml file's DOCTYPE node using a boost property tree?

我找到了一些关于如何使用 boost 属性 树读取 xml 文件的精彩示例。然而,真正让我头疼的是提取 DOCTYPE 值。给定一个包含以下行的 xml 文件:

<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

如果我这样做:

// Create an empty property tree object
boost::property_tree::ptree pt;

// Load the XML file into the property tree.
boost::property_tree::read_xml(filenameIn, pt);

// and then immediately write it back out again...
boost::property_tree::write_xml(filenameOut, pt);

我希望内容(文件名输出)== 内容(文件名输入)。

但事实并非如此。特别是缺少 DOCTYPE 节点。因此,如何提取 DOCTYPE 节点的值?

你不能。

PropertyTree 是一个用于 serializing/deserializing 属性树的库,包含多种可能易于使用的格式。

PropertyTree 不是 XML 库。或者 JSON 库。

  • What XML parser should I use in C++? (I recommend PugiXML; Here's an answer where I used PugiXML to add the processing instruction: Add XML headers using Boost's property trees)

关于添加处理指令:可以使用API:

中未记载的部分
  • Add xml-stylesheet processing instructions to boost property_tree