Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ÔÚ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


Ïà¹ØÎĵµ£º

.net XML ¶ÁÈ¡ дÈë


Ò»¡¢¼òµ¥½éÉÜ
using System.Xml;
//³õʼ»¯Ò»¸öxmlʵÀý
XmlDocument xml=new XmlDocument();
//µ¼ÈëÖ¸¶¨xmlÎļþ
xml.Load(path);
xml.Load(HttpContext.Current.Server.MapPath("~/file/bookstore.xml"));
//Ö¸¶¨Ò»¸ö½Úµã
XmlNode root=xml.SelectSingleNode("/root");
//»ñÈ¡½ÚµãÏÂËùÓÐÖ±½Ó×Ó½Úµã
XmlNodeList ......

python·¢ÓʼþµÄ´úÂë

# -*- coding: cp936 -*-
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
import smtplib
 
#´´½¨Ò»¸ö´ø¸½¼þµÄʵÀý
msg = MIMEMultipart()
#¹¹Ô츽¼þ
att = MIMEText(open('e:\\test.txt').read(), 'base64', 'gb2312')
att["Content-Type"] = 'application/ ......

PythonµÄbug

PythonÌ«»ðÁË£¬²»Ñ§µã¶¼¸Ð¾õ×Ô¼º²»ÊÇѧ¼ÆËã»úµÄ£¬½ñÌì¿´Á˸ö²»´íµÄ¡¶¼òÃ÷python½Ì³Ì¡·£¬ºÜ²»´í¡£²»¹ýÔÚѧϰ¹ý³ÌÖУ¬¾ÓÈ»·¢ÏÖÁËÒ»¸öPythonµÄbug£¬
#!/usr/bin/python
#coding=UTF-8
class Person:
'''Represents a person.'''
population = 0
def __init__(self, name):
'''Initializes the person's data.'''
......

WebserviceÖзþÎñÆ÷¶ËÖ±½Ó²Ù×÷SOAPµÄXMLÄÚÈÝ

ͨ³£Çé¿öÏÂ,ÔÚJAX-WS2.0ÖÐÊÇÀûÓÃJAXB½«´«ÈëµÄSOAP XMLÏûϢת»»³ÉJAVAµÄobject,È»ºóµ÷ÓöÔÓ¦porttypeµÄJAVAÀàµÄÏàÓ¦µÄ·½·¨,ÔÚÍê³Éµ÷Óúó,ÔÙͨ¹ýJAXB½«·µ»Ø²ÎÊýת³ÉSOAP XML.
JAX-WS»¹ÌṩÁËÁíÒ»ÖÖ·½·¨,ÈÃÎÒÃÇ¿ÉÒÔÖ±½Ó²Ù×÷SOAP XML,ͨ¹ýÈöÔÓ¦porttypeµÄJAVAÀàʵÏÖ Provider<Source>½Ó¿Ú,µ±·þÎñÆ÷¶ËÊÕµ½SOAPÏûÏ¢ºó,»áµ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ