ÔÚpythonÖд¦ÀíXML×ܽá
±¾ÎÄ×ܽáÁËÔÚPythonÖÐÖ÷ÒªµÄ¼¸ÖÖ´¦ÀíXMLµÄ·½·¨£º
Element Tree
SAX
Dom
ʹÓõÚÈý·½Àà¿âÈçAmara 2.x£¬ libxml2dom µÈ
Element Tree
Element TreeÊÇPython 2.5ÒýÈëµÄʹÓüòµ¥£¬¿ì½ÝµÄ´¦Àí·½·¨£¬ Ò²ÊÇPython±ê×¼Àà¿âÍÆ¼öµÄ´¦ÀíXMLµÄ·½·¨¡£
ËüʹÓÃÊ÷ÐνڵãµÄÐÎʽÀ´¶ÁдXML¡£Element TreeÊÇÇáÁ¿¼¶µÄDOM£¬ ËùÒÔʹÓ÷½±ãÇÒºÄ×ÊÔ´ÉÙ¡£
±ÈÈçÓÐÒÔÏÂXMLÎļþ£º sample.xml
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user id="001">
<name>John</name>
<age>25</age>
<phone>12345</phone>
</user>
<user id="002">
<name>Bill</name>
<age>30</age>
<phone>54321</phone>
</user>
<user id="003">
<name>Rex</name>
<age>35</age>
<phone>88888</phone>
</user>
</users>
ʵÀý´úÂëÈçÏ£º
# -*- coding: utf-8 -*-
import sys
from xml.etree import ElementTree as ET
# ´òÓ¡user½Úµã£¬¸ñʽΪtag£ºtext
def printUser(user):
print "\nid:\t%s" % user.attrib.get('id')
for e in user.getchildren():
print "%s:\t%s" % (e.tag, e.text)
if __name__ == '__main__':
xmlFile = 'sample.xml'
# ½âÎösample.xml
doc = ET.parse(xmlFile)
users = doc.getroot()
# ±éÀúËùÓÐuser£¬´òÓ¡idºÍname
for user in users.findall('user'):
print "ID: %s\tName: %s" % (user.attrib['id'], user.find('name').text)
# ÕÒ³öidÊÇ001µÄuser
user1 = None
for user in users.getiterator('user'):
if user.attrib.get('id') == '001':
user1 = user
# ½«userµÄphone¸ÄΪ999£¬ ÔÙ´òÓ¡Õâ¸öuser½Úµã
if user1 != None:
printUser(user1)
user1.find('phone').text = '9999'
print ET.tostring(user1, 'utf-8')
# ɾ³ýnameΪRexµÄuser
for user in users.getiterator('user'):
if user.find('name').text == 'Rex':
use
Ïà¹ØÎĵµ£º
Ajax(Asynchronous JavaScript and XML)˵µ½µ×¾ÍÊÇÒ»ÖÖä¯ÀÀÆ÷Òì²½¶ÁÈ¡·þÎñÆ÷ÉÏXMLÄÚÈݵļ¼Êõ¡£ÏÖÔڵļ¼Êõ·²ÊǸúXML³¶ÉϹØÏµ£¬ÔÙ¼ÓÉϸö¸ÅÄî×ö»Ï×Ó£¬¾ÍÏñ½ð×°ÁËÒ»Ñù£¬×§µÃ²»ÐС£ÃÅÍâ µÄÈË¿´µÃºÜÊÇÈÈÄÖ£¬ÃÅÀïµÄÈËÒ¡Ò¡Í·²»ÍâÈçÊÇ¡£XMLÄØ£¬¿çƽ̨µÄг±ÓïÑÔ£¿ÆäʵXML£½TXT¡£
XMLÖ»ÊÇ·ûºÏºÜ¶à¹æ·¶µÄÎı¾¡£Ëü±¾Éíʲô¶¼²»ÊÇ£¬Ö ......
JAXB¸ÅÒª
JAXBΪJava Architecture for XML BindingµÄËõд£¬ÒâΪXML°ó¶¨µÄJAVA¿ò¼Ü¡£ËüÌṩÁËÒ»Ì׿ÉÒÔ¼òµ¥´æÈ¡XMLÊý¾ÝµÄAPI£¬Í¬Ê±£¬JAXB¿ÉÒÔ¸ù¾ÝXMLµÄschema×Ô¶¯Éú³É²Ù×÷XMLµÄJAVAÀà¡£ÀûÓÃJAXB£¬Ê¹ÓÃJAXB×Ô¶¯Éú³ÉµÄ²Ù×÷XMLµÄJAVAÀ࣬¿ÉÒÔ»ù±¾Éϲ»Óÿ¼ÂÇXML½á¹¹¶ø¼òµ¥µØ´æÈ¡XMLÊý¾Ý¡£
JAXBµÄÏÂÔØÓë°²×°
JAXBÖÁÉÙÐèÒªµ¼ÈëÒ ......
XMLÎļþÓÉÓÚÆäÀ©Õ¹ÐÔÓë¼æÈÝÐÔµÄÓŵ㣬±»¹ã·ºÓÃ×÷Èí¼þºÍϵͳµÄÅäÖÃÎļþ¡£ÕâÀï¼òÒª½éÉÜÒ»ÏÂQTÏÂÈçºÎÀ´½âÎöXMLÎļþ¡£
Ô´´úÂ룺
xml_reader.h
#ifndef XML_READER_H
#define XML_READER_H
#include <QtCore>
//#include <QtGui>
class xml_reader : public QXmlStreamReader
{
//Q_OBJECT
public:
......
ÔËÐÐÒ»¾äpythonÃüÁî
¶ÔvcÉèÖ÷¾¶
include:D:\PYTHON31\INCLUDE
lib:D:\PYTHON31\LIBS
#include "stdafx.h"
#include "python.h"
int main(int argc, char* argv[])
{
Py_Initialize() ;
PyRun_SimpleString("print('Hello')");
//PyRun_SimpleString("print(dir())");
Py_Finalize();& ......
ʹÓÃXmlDocumentÀàÍê³É¶ÔXMLµÄ²é¡¢É¾¡¢Ìí¡¢¸Ä
http://www.aspdiy.net/article/53.htm
ºǫ́C#´úÂë
1using System;
2using System.Collections;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System. ......