为什么这个循环只运行一次? noteDatabaseItem只需要一个节点并填充数据。 xml里面有3个注释。为什么这个循环只运行一次?
XML:
<?xml version="1.0" encoding="utf-8"?>
<noteCollection>
<note name="Test Note 1">This is test note 1 content!</note>
<note name="Test Note 2">This is test note 2 content!</note>
<note name="Test Note 3">This is test note 3 content!</note>
</noteCollection>
C++:
std::vector<notekeeper::noteDatabaseItem> noteList;
TiXmlElement* noteCollection = xmlDoc->FirstChildElement("noteCollection");
TiXmlElement* node = noteCollection->FirstChildElement("note");
int itemCount = 0;
while (node != NULL) {
itemCount++;
noteList.resize(itemCount);
noteList.push_back(noteDatabaseItem(node));
node = noteCollection->NextSiblingElement("note");
}
为什么在'push_back'之前'调整大小'?它调整自己。也许最后一行应该是'node = note-> NextSiblingElement(“note”);'? – GManNickG 2010-10-09 22:09:14
加载的XML是上面的,有3个音符,所以没有1,调整大小是一个错误,谢谢。 – Will03uk 2010-10-09 22:10:57
node = node-> NextSiblingElement(“note”);工作。 – Will03uk 2010-10-09 22:13:41