如何使用 boost.Qi 解析此类 XML 并调用名为标签的函数?
所以我知道有官方教程 Boost.Qi XML 解析 但我完全不知道如何解析这样的 XML:
<host url="http://www.site.com"/>
<run app="myApp" version=443 url="/folderName/innerFolder/myApp.exe"/>
<folder name="folderName" version=443>
<folder name="innerFolder" version=443>
<file name="innerFile.txt" version=443 url="/folderName/innerFolder/innerFile.txt">
<file name="myApp" version=443 url="/folderName/innerFolder/myApp.exe"/>
</folder>
<file name="fileName" url="/folderName/fileName.exe" version=442/>
</folder>
它看起来很简单,但我不知道如何解析我的 xml..( 我需要的很简单- 调用函数(使用与主机()的 file() 等标签相同的名称调用) 我需要发送到函数对象,例如:
typedef boost::variant<int, std::string, void*> variant_type;
std::map<std::string, variant_type> tagObj;
tagObj["url"] = 10;
那么 - 如何使 boost.Qi 解析我的 XML 并在解析时调用我的函数?
so I know there are official tutorials on Boost.Qi XML parsing but I steel quite do not get how to parse with it such XML:
<host url="http://www.site.com"/>
<run app="myApp" version=443 url="/folderName/innerFolder/myApp.exe"/>
<folder name="folderName" version=443>
<folder name="innerFolder" version=443>
<file name="innerFile.txt" version=443 url="/folderName/innerFolder/innerFile.txt">
<file name="myApp" version=443 url="/folderName/innerFolder/myApp.exe"/>
</folder>
<file name="fileName" url="/folderName/fileName.exe" version=442/>
</folder>
It looks quite simple but I steel do not get how to parse my xml..( What I need is simple - call a function (called with same name as tag like file() of host()) I need to sent to functions objects like:
typedef boost::variant<int, std::string, void*> variant_type;
std::map<std::string, variant_type> tagObj;
tagObj["url"] = 10;
So - how to make boost.Qi parse my XML and call my functions while parsing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有一个有效的示例(今天早上我也正在查看 xml 解析器示例),但我想说您想将此规则更改
为
tag_struct 是一个
BOOST_FUSION_ADAPT_STRUCT
,它接受诸如 < code>文件夹名称,版本
url
等然后是来自example 应该或多或少相同 - 您将需要更改 xml_mini_printer 进行输出。作为练习,我自己会尝试一下。如果我到达任何地方都会更新。编辑:呸,我被困住了!
I haven't got a working example yet (I am going through the xml parser example this morning too) but I would say you want to change this rule
to
where tag_struct is a
BOOST_FUSION_ADAPT_STRUCT
that accepts things likefolder name
,version
url
etc Then the code from the example should then be more or less the same - you will need to change the xml_mini_printer for output. I will have a go at this myself as an exercise. Will update if I get anywhere.EDIT: Bah I'm stuck!