2017-06-28 21 views
1

私はboost C++ライブラリを初めて使用していましたが、これを使ってxmlドキュメントを解析したいと思っていましたが、ロジックの把握に問題があります。C++のBoost XML Parser

<?xml version="1.0"?> 
<GCC_XML version="0.9.0" cvs_revision="1.140"> 
    <Function id="_6" name="A" returns="_12" context="_1" location="f1:1" file="f1" line="1" mangled="_Z1Aif"> 
    <Argument name="a" type="_12" location="f1:1" file="f1" line="1"/> 
    <Argument name="c" type="_13" location="f1:1" file="f1" line="1"/> 
    </Function> 
    <Function id="_7" name="B" returns="_14" context="_1" location="f1:7" file="f1" line="7" mangled="_Z1Bf"> 
    <Argument name="d" type="_13" location="f1:7" file="f1" line="7"/> 
    </Function> 
</GCC_XML> 

私はどのように私はそれについて移動する必要があり、各機能タグの引数タグにアクセスしたい場合は?私はファンクションタグに次のようにアクセスできました。

BOOST_FOREACH(ptree::value_type const& v, pt.get_child("GCC_XML")) { 
     if(v.first == "Function") { 
      cout << "Function name : " << v.second.get_child("<xmlattr>.name").data() << endl; 
      cout << "Function return type : " << v.second.get_child("<xmlattr>.returns").data() << endl; 
} 

答えて

1

BoostにはXMLライブラリがありません。これは、プロパティツリーライブラリを持っています。邪魔にならないように、単に正確に同じことを行うことを

BOOST_FOREACH(ptree::value_type const& a, v) { 
    if(a.first == "Argument") { 
     cout << "Argument name : " << a.second.get_child("<xmlattr>.name").data() << endl; 
     cout << "Argument type : " << a.second.get_child("<xmlattr>.type").data() << endl; 
    } 
} 
+0

は助けをありがとうございました。 –