Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个如下所示的 xml 文件
<siteinfo> ... </siteinfo> <page> <title>...</title> <revision> ... <revision> </page>
它没有根/封闭节点,所以我在运行我的程序时得到“文档末尾的额外内容”。使用 libxml 打开文件进行解析后,有没有办法轻松地将这个根/封闭节点添加到解析树中?
如果您无法更改源 XML 的结构,更简单的方法是创建如下字符串:
string xml = string("<root>") + file_contents + string("</root>");
然后你就可以轻松解析这个字符串了。顺便说一句,由于您使用的是 C++,因此您应该尝试一下 libxml++。它是 libxml 的 C++ 包装器,非常好。