ʹÓÃ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-
Ïà¹ØÎĵµ£º
ÀûÓÃsqlhelperÖеÄExcuteXmlReader·½·¨£¬¶ÁÈ¡Êý¾Ý²¢±£´æÎªxmlÎļþ
string strConn = Properties.Settings.Default.Connections;
SqlConnection connection = new SqlConnection(strConn);
& ......
/*
* XMLTool.h ÅäÖÃÎļþ½âÎö¶¯Ì¬¿âÍ·Îļþ
* Ö÷ÒªÊä³öº¯Êý½Ó¿Ú·Ö±ðʵÏÖ¶ÔÅäÖÃÎļþµÄ¶ÁÈ¡ºÍдÈ룬Õë¶Ô½á¹û¼¯µÄ¸´ÖÆÇå¿Õ£¬ºÍÁ½¸ö×Ö·û´®´¦Àíº¯Êý
* ¶ÁÈ¡ÅäÖÃÎļþ½Ó¿Ú £ºint ReadXMLFile(XML_Node_Vector *XmlNodeVector, string filepath);
* дÈëÅäÖ ......
java ´úÂë
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList; ......
Javaͨ¹ýXML SchemaУÑéXML
XMLµÄУÑéÔÚXML´¦ÀíÖзdz£³£¼û£¬Èç¹ûûÓÐÓÐЧµÄ°ì·¨À´Ð£ÑéXMLµÄºÏ·¨ÐÔ£¬ÍùÍù»áµ¼ÖºܶàÎÊÌâ¡£
XMLµÄУÑéÊÇͨ¹ýXML Schema£¨XSD£© »òDTDÎļþµÄÓï·¨¹æ·¶À´Ð£ÑéµÄ¡£DTDÏÖÔÚÔ½À´Ô½²»ÊÜ»¶ÓÁË£¬ÔÚ´ËÑ¡ÓÃXSDÀ´Ð£Ñé¡£
JavaУÑéXMLÊǼþºÍ³¶µµÄÊÂÇ飬ÒòΪSunµÄXMLÏà¹ØÈí¼þ°ü» ......
xmlΪ£º
<friendShares>
<totalCount>352</totalCount>
<friendShare>
<code>XXXXXXX</code>
<date>2010-01-15T00:00:00+08:00</date>
<friendId>499</friendId>
<movie>
<code>XXXXXX</code>
<contentId>89718</content ......