ʹÓÃ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-
Ïà¹ØÎĵµ£º
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 ......
µ±Ò³ÃæÔØÈëʱ£¬»áÖ´ÐÐλÓÚ body ²¿·ÖµÄ JavaScript¡£
µ±±»µ÷ÓÃʱ£¬Î»ÓÚ head ²¿·ÖµÄ JavaScript ²Å»á±»Ö´ÐС£
2006Äê1ÔÂ14ÈÕ£¬John Resig ÔÚBarCampNYCÉϵÚÒ»´Î·¢²¼ÁËjQuery¡£
JSON(JavaScript Object Notation) ÊÇÒ»ÖÖÇáÁ¿¼¶µÄÊý¾Ý½»»»¸ñʽ¡£Ò×ÓÚÈËÔĶÁºÍ±àд¡£Í¬Ê±Ò²Ò×ÓÚ»úÆ÷½âÎöºÍÉú³É¡£Ëü»ùÓÚJavaScript£¨St ......
/*
* 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; ......
package com.beckham.dom;
import java.io.File;
import java.io.FileWriter;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
/**
* @author ×÷Õß<Beckham>
* Email:gaowm0207@gmail.com ......