ʹÓÃTinyXml½âÎöXmlʾÀý
// TestXml.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include "tinyxml.h"
#include "lang.h"
#include <string>
using namespace std;
using namespace std;
#pragma comment(lib, "tinyxmld.lib")
BOOL LoadXml(TiXmlDocument&doc, LPCTSTR lpszSrcPath);
BOOL SaveXml(TiXmlDocument&doc, LPCTSTR lpszDstPath);
BOOL GetDeclare(TiXmlDocument&doc);
BOOL ReadXmlText(TiXmlDocument&doc);
BOOL ParseXmlText(TiXmlElement* pEleRoot);
BOOL ReadXmlAttr(TiXmlDocument&doc);
BOOL ParseXmlAttr(TiXmlElement* pEleRoot);
BOOL AddNode(TiXmlDocument& doc);
BOOL DelNode(TiXmlDocument& doc);
int _tmain(int argc, _TCHAR* argv[])
{
TiXmlDocument doc;
//load xml
if (!LoadXml(doc, "./test_copy.xml"))
{
return -1;
}
//get declare
GetDeclare(doc);
//add and del
DelNode(doc);
AddNode(doc);
cout << "============================Read Text==========================" << endl;
//read text
ReadXmlText(doc);
cout << "============================Read Attribute==========================" << endl;
//read attribute
ReadXmlAttr(doc);
if (!SaveXml(doc, "./test2.xml"))
{
return -1;
}
return 0;
}
BOOL LoadXml(TiXmlDocument&doc, LPCTSTR lpszSrcPath)
{
//load file
if (!doc.LoadFile(lpszSrcPath))
{
cout << "load xml failed!" << endl;
return FALSE;
}
//print
doc.Print();
return TRUE;
}
BOOL SaveXml(TiXmlDocument&doc, LPCTSTR lpszDstPath)
{
//save file
if (!doc.SaveFile(lpszDstPath))
{
cout << "save xml failed!" << endl;
}
else
{
cout << "save xml succ!" << endl;
}
return TRUE;
}
BOOL GetDeclare(TiXmlDocument&doc)
{
TiXmlNode* pXmlFirst = doc.FirstChild();
if (NULL != pXmlFirst)
{
TiXmlString str;
TiXmlDeclaration* pXmlDec = pXmlFirst->ToDeclaration();
if (NULL == pXmlDec)
{
pXmlDec-
Ïà¹ØÎĵµ£º
ÔÚXMLÎĵµÖеÄËùÓÐÎı¾¶¼»á±»½âÎöÆ÷½âÎö¡£
Ö»ÓÐÔÚCDATA²¿¼þÖ®ÄÚµÄÎı¾»á±»½âÎöÆ÷ºöÂÔ¡£
½âÎöÊý¾Ý
XML ½âÎöÆ÷ͨ³£Çé¿öÏ»ᴦÀíXMLÎĵµÖеÄËùÓÐÎı¾¡£
µ±XMLÔªËØ±»½âÎöµÄʱºò£¬XMLÔªËØÄÚ²¿µÄÎı¾Ò²»á±»½âÎö:
<message>This text is also parsed</message>
XML½âÎöÆ÷ÕâÑù×öµÄÔÒòÊÇXMLÔªËØÄÚ²¿¿ÉÄÜ» ......
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
private XmlDo ......
ÀûÓÃsqlhelperÖеÄExcuteXmlReader·½·¨£¬¶ÁÈ¡Êý¾Ý²¢±£´æÎªxmlÎļþ
string strConn = Properties.Settings.Default.Connections;
SqlConnection connection = new SqlConnection(strConn);
& ......
/*
* XMLTool.h ÅäÖÃÎļþ½âÎö¶¯Ì¬¿âÍ·Îļþ
* Ö÷ÒªÊä³öº¯Êý½Ó¿Ú·Ö±ðʵÏÖ¶ÔÅäÖÃÎļþµÄ¶ÁÈ¡ºÍдÈ룬Õë¶Ô½á¹û¼¯µÄ¸´ÖÆÇå¿Õ£¬ºÍÁ½¸ö×Ö·û´®´¦Àíº¯Êý
* ¶ÁÈ¡ÅäÖÃÎļþ½Ó¿Ú £ºint ReadXMLFile(XML_Node_Vector *XmlNodeVector, string filepath);
* дÈëÅäÖ ......