从 C++/Unix 中的字符串读取 XML [英] Read XML from a string in C++ / Unix

查看:40
本文介绍了从 C++/Unix 中的字符串读取 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种简单的方法来读取包含在 Unix 系统的 C++ 字符串变量中的 XML.我找到了很多 xml 文件的解决方案,但关于包含在字符串变量中的 XML 的解决方案并不多.

I'm looking for a simple way to read XML that is contained in a string variable in C++ for Unix systems. I have found a lot of solutions for xml files but not a lot about XML that is contained in a string variable.

我是否必须使用 find() 等函数,或者是否有我错过的库可以为我完成这项工作?

Do I have to use functions such as find(), etc. or is there a library that I missed that could do the job for me ?

如果我在字符串中有以下 XML,我该如何读取它?(以 pugixml 为例)

If I have the following XML in a string, how can I read it ? (with pugixml for example)

string xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
     xml += "<people><person><name>Toto</name><age>20</age></person>";
     xml += "<person><name>John</name><age>42</age></person></people>";

推荐答案

我建议使用 Tinyxml2 库.尤其是 XMLDocument::Parse - 是您最好的捕获 (

I would recommend to use Tinyxml2 library. Especially XMLDocument::Parse - is your best catch (http://grinninglizard.com/tinyxml2docs/classtinyxml2_1_1_x_m_l_document.html#a1819bd34f540a7304c105a6232d25a1f)

在 XMLDocument 中加载字符串后 - 您可以通过 tinyxml2 工具进一步导航.

And after loading your string in XMLDocument - you can navigate it via tinyxml2 tools further.

文档中的确切示例 -> http://www.grinninglizard.com/tinyxml2docs/_example-3.html

Exact example in documentation -> http://www.grinninglizard.com/tinyxml2docs/_example-3.html

这篇关于从 C++/Unix 中的字符串读取 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆