Tixml主页上给的一个遍历方法

void dump_to_stdout(TiXmlNode* pParent)  
{
	if (!pParent) return;

	TiXmlNode* pChild;
	TiXmlText* pText;
	int t = pParent->Type();
	printf("type %d \n", t);

	switch (t)
	{
	case TiXmlNode::TINYXML_DOCUMENT:
		printf("Document");
		break;
	case TiXmlNode::TINYXML_ELEMENT:
		printf("Element [%s]", pParent->Value());
		break;
	case TiXmlNode::TINYXML_COMMENT:
		printf("Comment: [%s]", pParent->Value());
		break;
	case TiXmlNode::TINYXML_UNKNOWN:
		printf("Unknown");
		break;
	case TiXmlNode::TINYXML_TEXT:
		pText = pParent->ToText();
		printf("Text: [%s]\n", pText->Value());
		break;
	case TiXmlNode::TINYXML_DECLARATION:
		printf("Declaration");
		break;
	default:
		break;
	}
	printf("\n");
	system("PAUSE");
	for (pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling())
	{
		dump_to_stdout(pChild);
	}
}

你可能感兴趣的:(tinyxml)