tinyXML链接疏失!11急
tinyXML链接出错!!!!!!!!!!!!11急急急!!!!!!
最近在研究tinyxml操作XML文件,
这是我的代码:(写的很乱,仅测试用。。。)
最近在研究tinyxml操作XML文件,
这是我的代码:(写的很乱,仅测试用。。。)
- C/C++ code
#include "tinyxml.h" #include <iostream> using namespace std; void main( int argc, char*argv[] ) { TiXmlDocument doc; TiXmlElement* pmsg = NULL; TiXmlDeclaration *pdecl = new TiXmlDeclaration( "1.0", "",""); if ( NULL ==pdecl ) { return; } doc.LinkEndChild( pdecl ); TiXmlElement *pRoot = new TiXmlElement( "MyApp" ); if ( NULL ==pRoot ) { return; } doc.LinkEndChild( pRoot );//¸ùÔªËØ TiXmlComment *pComment = new TiXmlComment(); if ( NULL == pComment ) { return; } pComment->SetValue( "Setting for MyApp" ); pRoot->LinkEndChild( pComment ); TiXmlElement *pMsgs = new TiXmlElement( "Messages" ); if ( NULL == pMsgs ) { return; } pRoot->LinkEndChild( pMsgs ); pmsg = new TiXmlElement( "Welcome" ); pmsg->LinkEndChild( new TiXmlText( "Welcome to MyApp" ) ); pMsgs->LinkEndChild( pmsg ); pmsg = new TiXmlElement( "FaraWell" ); pmsg->LinkEndChild( new TiXmlText( "Thhank you for using MyApp" ) ); pMsgs->LinkEndChild( pmsg ); TiXmlElement *pWindows = new TiXmlElement( "Windows" ); pRoot->LinkEndChild( pWindows );//¸ùÔªËØÖвåÈëÐÂÔªËØWindows pWindows->SetAttribute( "name", "MainFrame"); pWindows->SetAttribute( "x", 5 ); pWindows->SetAttribute( "y", 15 ); pWindows->SetAttribute( "w", 400 ); pWindows->SetAttribute( "h", 250 ); TiXmlElement *pCxn = new TiXmlElement( "Connection" ); pRoot->LinkEndChild( pCxn ); pCxn->SetAttribute( "ip", "192.168.0.1" ); pCxn->SetDoubleAttribute( "timeout", 123.456 ); //dump_to_stdout( &doc ); bool isOk = doc.SaveFile( "E:\\cjbtest\\TinyXMLdemo\\test1\\appsetting.xml" ); TiXmlDocument *pDocument = new TiXmlDocument( "E:\\cjbtest\\TinyXMLdemo\\test1\\appsetting.xml" ); if ( NULL != pDocument ) { if ( !pDocument->LoadFile() ) { return; } TiXmlElement *pRootElement = pDocument->FirstChildElement( "MyApp" ); if ( NULL != pRootElement ) { TiXmlElement *pMsgElement = pRootElement->FirstChildElement( "Messages" ); if ( NULL != pMsgElement ) { TiXmlElement *pWelElement = pMsgElement->FirstChildElement( "Welcome" ); if ( NULL != pWelElement ) { std::cout<<pWelElement->GetText()<<std::endl; } TiXmlElement *pFarawell = pWelElement->NextSiblingElement( "FaraWell" ); if ( NULL != pFarawell ) { std::cout<<pFarawell->GetText()<<std::endl; } } else { return; } TiXmlElement *pWindowsElement = pMsgElement->NextSiblingElement( "Windows" ); if ( NULL != pWindowsElement ) { TiXmlAttribute *pFistAttribute = pWindowsElement->FirstAttribute(); if ( NULL != pFistAttribute ) { std::cout<<pFistAttribute->IntValue()<<std::endl; } TiXmlAttribute *pSecond = pFistAttribute->Next(); if ( NULL != pSecond ) { std::cout<<pSecond->IntValue()<<std::endl; } TiXmlAttribute *pth = pSecond->Next(); if ( NULL != pth ) { std::cout<<pth->IntValue()<<std::endl; } TiXmlAttribute *pFouth = pth->Next(); if ( NULL != pFouth ) { std::cout<<pFouth->IntValue()<<std::endl; } } else { } TiXmlElement *pConnection = pWindowsElement->NextSiblingElement( "Connection" ); if ( NULL != pConnection ) { TiXmlAttribute *pConFist = pConnection->FirstAttribute(); if ( NULL != pConFist ) { std::cout<<pConFist->Value()<<std::endl; } TiXmlAttribute *pConSec = pConFist->Next(); if ( NULL != pConSec ) { std::cout<<pConSec->DoubleValue()<<std::endl; } } else { return; } } else { return; } } }