2

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?

4

1 回答 1

2

我还没有一个可行的示例(我今天早上也在查看 xml 解析器示例)但我会说你想更改此规则

qi::rule<Iterator, std::string(), ascii::space_type> start_tag;

qi::rule<Iterator, tag_struct(), ascii::space_type> start_tag;

其中 tag_struct 是一个BOOST_FUSION_ADAPT_STRUCT接受诸如folder name等之类的东西然后示例version url中的代码应该或多或少相同 - 您将需要更改 xml_mini_printer 以进行输出。作为练习,我自己会尝试一下。如果我到达任何地方会更新。

编辑:呸,我被困住了!

于 2011-03-12T10:46:20.717 回答