如下是这个xml文件的内容,
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Info>
<SingleCity CityCode="010">
<stu_name>hami</stu_name>
</SingleCity>
<SingleCity CityCode="020">
<stu_name>hami2</stu_name>
</SingleCity>
<SingleCity CityCode="021">
<stu_name>hami3</stu_name>
</SingleCity>
</Info>
我用以下代码循环判断SingleCity的个数
- C/C++ code
TiXmlElement *personElement = personDoc->RootElement(); TiXmlElement*SiblingElement = personElement->FirstChildElement(); int i=0; while ( SiblingElement != NULL ) { i++; cout<<SiblingElement->Value()<<endl; SiblingElement = SiblingElement->NextSiblingElement(); }
可是通过跟踪调试,SiblingElement 就是无法遍历到<SingleCity CityCode="021">,求各位网友给点提示,谢谢!
------解决方案--------------------
TiXmlElement *personElement = personDoc->RootElement();
TiXmlElement*pElem= personElement->FirstChildElement();
for( pElem; pElem; pElem=pElem->NextSiblingElement())
{
cout<<pElem->Value()<<endl;
}