提高认识一个孩子 [英] boost recognize a child

查看:147
本文介绍了提高认识一个孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是有关:<一href=\"http://stackoverflow.com/questions/26764813/find-key-in-xml-with-boost/26766166?noredirect=1#comment42145415_26766166\">boost

有些升压code的正常工作,发现一个节点有孩子,但如果一个节点有其他两个节点它不承认孩子。

Some of the boost code is working correctly to find that a node has child, but if one node have two other nodes it didn't recognize the children.

这是递归调用能够读取所有的树节点,然后将该值的副本适用于谷歌的协议缓冲

It's recursive call to be able to read all the tree nodes and then apply the copy of the value to the google protocol buffer

void ReadXML(iptree& tree, string doc)
{
    const GPF* gpf= pMessage->GetGPF();
    for(int i = 0 ; i < gpf->field_count(); ++i)
    { 
          string fieldName = GetName(i);
          boost::optional< iptree & > chl =  pt.get_child_optional(fieldName); 
          if(chl) { 
          for( auto a : *chl ){
             boost::property_tree::iptree subtree = (boost::property_tree::iptree) a.second ;
             assignDoc(doc);
                 ReadXML(subtree, doc);
             }
           }
      }     
}

XML文件

<?xml version="1.0" encoding="utf-8"?>
<nodeA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <nodeA.1>This is the Adresse</nodeA.1>
    <nodeA.2>
    <node1>
      <node1.1>
        <node1.1.1>Female</node1.1.1>
        <node1.1.2>23</node1.1.2>
        <node1.1.3>Engineer</node1.1.3>
      </node1.1>
      <node1.1>
        <node1.2.1>Female</node1.2.1>
        <node1.2.2>35</node1.2.2>
        <node1.2.3>Doctors</node1.2.3>
      </node1.1>
    </node1>
</nodeA.2>
<nodeA.3>Car 1</nodeA.3>
</nodeA>

我的问题是,节点1 不被识别为有孩子的。我不知道这是否是因为有两个孩子同名的节点。

My problem is that node1 is not recognised as having child. I don't know if it's because there are two children nodes with the same name.

请注意,该XML文件可从一个客户端切换到另一个。我可能有不同的节点。

Note that the XML files may change from one client to another. I may have different nodes.

我必须使用 a.second a.first

推荐答案

下面

boost::optional< iptree & > chl =  pt.get_child_optional(fieldName);

您明确地搜索一个孩子给定的名称。这个名字似乎永远不会递归过程中的变化。在各个层面上你看看它似乎同名儿童。

you explicitly search for a child with a given name. This name never seems the change during recursion. On every level you look for children with the same name it seems.

这篇关于提高认识一个孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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