// xml_0.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
 
#include "tinyxml//XML.h"
#include <iostream>

void createXML()
{
	CXML xml;
	xml.addXmlDeclaration("1.0","gb2312","");
	TiXmlElement* root=xml.addXmlRootElement("fields");
	TiXmlElement* pElement=xml.addXmlChildElement(root,"pos");
	xml.addXmlAttribute(pElement,"x","100");
	xml.addXmlAttribute(pElement,"y","200.1");
	xml.addXmlAttribute(pElement,"z","0.123");

	TiXmlElement* pElement2=xml.addXmlChildElement(root,"dest");
	xml.addXmlAttribute(pElement2,"x","一二三");
	xml.addXmlAttribute(pElement2,"y","一二");
	xml.addXmlAttribute(pElement2,"z","一");
	xml.saveFile("1.xml"); 
}

void CreateXML1()
{
	CXML xml;
	xml.addXmlDeclaration();
    TiXmlElement* root=xml.addXmlRootElement("fields");
	xml.addXmlComment(root,"AAAAAAA");
	TiXmlElement* pElement=xml.addXmlChildElement(root,"pos_x");
	xml.addElementValue(pElement,"1.3");
	pElement=xml.addXmlChildElement(root,"pos_x");
	xml.addElementValue(pElement,"30.1");
	pElement=xml.addXmlChildElement(root,"pos_x");
	xml.addElementValue(pElement,"30ssss.1");
	xml.saveFile("2.xml");
}


void LoadXML()
{
	CXML xml;
	xml.ParseXmlFile("1.xml");
	string a;
	TiXmlElement* pElement=xml.GetElement("fields","dest"); 
  	xml.getElementAttributeValue(pElement,"x",a);
 	cout<<a<<endl;
 	xml.getElementAttributeValue(pElement,"y",a);
 	cout<<a<<endl;
 	xml.getElementAttributeValue(pElement,"z",a);
 	cout<<a<<endl;
}

void LoadXML1()
{
	CXML xml;
	xml.ParseXmlFile("2.xml");
	string a;
	xml.getFirstElementValue("pos_x",a);
	cout<<a<<endl; 
	xml.getNextElementValue("pos_x",a);
 	cout<<a<<endl;
	xml.getNextElementValue("pos_x",a);
	cout<<a<<endl;
}

int _tmain(int argc, _TCHAR* argv[])
{
// 	createXML();
// 	LoadXML();  
 	CreateXML1();
 	LoadXML1();  
	getchar();
	return 0;
}

