65,186
社区成员




void findAllLabel(XMLElement* next)
{
XMLElement *pLable = next->FirstChildElement("Label")
if (pLable)
{
cout<<pLable->GetText();
}
XMLElement *nextChild = next->FirstChildElement("Question")
while(nextChild)
{
findAllLabel(nextChild);
nextChild = nextChild->NextSiblingElement();
}
}
<?xml version="1.0" encoding="utf-8"?>
<Questions Project="simple_survey" Context="Question" >
<Question QuestionFullName="Respondent" QuestionType="Block" IsSystem="true">
<Label>Variables reserved for respondent identification</Label>
<Question QuestionName="Serial" QuestionFullName="Respondent.Serial" IsSystem="true" >
<Label>Serial number</Label>
<HelperFields>
<Question QuestionName="SourceFile" QuestionFullName="Respondent.Serial.SourceFile" IsSystem="true" >
<Label>What source file (for example, TIFF) can be used to get the respondent's serial number?</Label>
</Question>
</HelperFields>
</Question>
</Questions>
您这个有点问题,死循环了
void findAllLabel(XMLElement* next)
{
XMLElement *pLable = next->FirstChildElement("Label")
if (pLable)
{
cout<<pLable->GetText();
}
XMLElement *nextChild = next->FirstChildElement("Question")
while(nextChild)
{
findAllLabel(next);
nextChild = nextChild->NextSiblingElement();
}
}
未测试,你试一下吧,递归一定要只处理本层的事务,才不会混乱。void findAllLabel(XMLElement* next)
{
if(next->FirstChildElement("Question"))
{
next = next->FirstChildElement("Question");
string str = next->FirstChildElement("Label")->GetText();
cout<<str<<endl;
}
else
{
XMLElement *neighbor = next->NextSiblingElement();
while(neighbor)
{
string str1 = neighbor->FirstChildElement("Label")->GetText();
cout<<str1<<endl;
neighbor = neighbor->NextSiblingElement();
}
next =
}
//XMLElement* nextElement = next->FirstChildElement("Question");
findAllLabel(next);
}