Linux c 开发-17 pugixml xml_node Collection和一个数组的值比较示例

xml_node lastnode = rootNode.last_child();

	if(lastnode == NULL)
	{
		newresult = TRUE;
	}
	else
	{
		newresult=true;
		while(lastnode!=NULL)
		{
			BOOL bSame=true;
			for(i=0;i<3;i++)
			{
				if((type[i] == NULL) || (value[i] == NULL))
				{
					break;
				}
				xml_attribute lastattribute=lastnode.attribute(type[i]);
				
				if(lastattribute == NULL)
				{
					newresult = TRUE;
					break;
				}
				if((strcmp(lastattribute.value(), arr[i]) != 0))
				{
					bSame=false;
					break;
				}
			}
			if(bSame==true)
			{
				newresult=false;
				break;
			}
			lastnode = lastnode.previous_sibling(strbuf);
		}
	}

  

自下往上查找,假如数组里存的是 zhangsan male 16,当在collection里找到的newresult返回false,否则返回true。

<person>

  <zhangsan sex="male" age="15" school="xx"/>

  <lisi sex="male" age="13" school="xx"/>

  <zhangsan sex="male" age="13" school="xx"/>

</person>

注意,最后一个节点zhangsan的 previous_sibling不是lisi而是第一个zhangsan。

1、建了一个小群:616945527(软件), 欢迎大家加入,加群口令abc123,硬件嵌入式开发者推荐75764412(单片机)。
闲置域名www.nsxz.com出售(等宽等高字符四字域名,可组合多种有意义词语)。
原文地址:https://www.cnblogs.com/zhaogaojian/p/14612807.html