#include "tinyxml.h"
#pragma comment ( lib , "tinyxml.lib" )
int test(int argc, _TCHAR* argv[])
{
TiXmlDocument doc;
TiXmlDeclaration* dec = NULL;
TiXmlElement* pElement = NULL;
TiXmlAttribute* pAttr = NULL;
TiXmlNode* pNode = NULL;
TiXmlNode* pRoot = NULL;
TiXmlNode* pHead = NULL;
TiXmlText* pText = NULL;
// 添加声明
dec = NULL;
dec = new TiXmlDeclaration( "1.0" , "GB18030" , "yes" );
if( dec != NULL )
{
pNode = NULL;
pNode = doc.LinkEndChild( dec );
if( pNode == NULL )
{
delete dec;
dec = NULL;
}
}
// 添加主结点
pElement = NULL;
pElement = new TiXmlElement( "LCMS" );
if( pElement != NULL )
{
pRoot = NULL;
pRoot = doc.LinkEndChild( pElement );
if( pRoot == NULL )
{
delete pElement;
pElement = NULL;
}
}
// 添加属性
pRoot->ToElement()->SetAttribute( "VERSION" , "1.2.2.0" );
pRoot->ToElement()->SetAttribute( "COMPANY" , "INFOGO" );
// 修改字段名
pRoot->ToElement()->SetValue( "ICS" );
// 添加内容
pText = NULL;
pText = new TiXmlText( "桌面管理、内网安全" );
if( pText != NULL )
{
pRoot->InsertEndChild( *pText );
delete pText;
pText = NULL;
}
// 添加子节点
pElement = NULL;
pElement = new TiXmlElement( "HEAD" );
if( pElement != NULL )
{
pHead = NULL;
pHead = pRoot->InsertEndChild( *pElement );
delete pElement;
pElement = NULL;
}
// 添加字段
pElement = NULL;
pElement = new TiXmlElement( "AgentId" );
if( pElement != NULL )
{
pText = NULL;
pText = new TiXmlText( "lcms_agent_0001" );
if( pText != NULL )
{
pElement->InsertEndChild( *pText );
delete pText;
pText = NULL;
}
pHead->InsertEndChild( *pElement );
delete pElement;
pElement = NULL;
}
return 0;
}
int main( int argc , _TCHAR* argv[] )
{
while( true )
{
test( argc , argv );
Sleep( 1 );
}
getchar();
}