python½âÎöxmlÎļþ
ʹÓÃxml.dom½âÎö¼¸Õ×µÄxmlÎļþ£¬·Ç³£»ºÂý£¬ÓÐÖÖ¼ÙËÀµÄ¸Ð¾õ¡£Ôõô½â¾ö£¿ÓÃÆäËû¿âÊÇ·ñ»áºÃЩ£¬ÔÝʱֻ֪µÀÕâ¸ö¿âµÄ¡£
Äã¿ÉÒÔÊÔÒ»ÏÂElementTree
pythonµÄ¹Ù·½Àý×Ó
import xml.parsers.expat
# 3 handler functions
def start_element(name, attrs):
print 'Start element:', name, attrs
def end_element(name):
print 'End element:', name
def char_data(data):
print 'Character data:', repr(data)
p = xml.parsers.expat.ParserCreate()
p.StartElementHandler = start_element
p.EndElementHandler = end_element
p.CharacterDataHandler = char_data
p.Parse(""" <?xml version="1.0"?>
<parent id="top"> <child1 name="paul">Text goes here </child1>
<child2 name="fred">More text </child2>
</parent>""", 1)
Ïà¹ØÎÊ´ð£º
Êý¾Ý¿â±íÖÐÓÐÒ»ÁУ¨TranXml£©ÀàÐÍÊÇxml£¬´æ´¢µÄÊÇÀàËÆ
<fathernode>
<a>aaa
</a>
<b>bbb
</b>
</fathernode>
µÄÐÅÏ¢£¬²¢ÇÒͨ¹ý²éѯ·½· ......
´ÓÊý¾Ý¿âÖвéѯһÕűíµÄÊý¾Ý
select ²¿ÃÅ,ÐÕÃû from tb
ÈçºÎ²ÅÄÜÉú³ÉÏÂÃæµÄxml¸ñʽ
XML code:
<folder state="unchecked" label="È«²¿">
¡¡¡¡ <folder state="unchecked&qu ......
ÒÑÖªÎļþ1.xmlºÍÊý¾ÝÎļþdb.xml£¬ÈçºÎÓÃjava±àд³ÌÐò£¬µÃ³ö2.xmlÎļþ£¿
1.ÒÑÖªxmlÎļþ 1.xml½á¹¹ÈçÏ£º
<cs>
<cs name="cs1" details="This is cs1" country="China&q ......
ÎÒÓÐÒ»¸öÀàËÆµÄxmlµÄ string£¬Ïëͨ¹ý±éÀúÔõô¸öxml Êä³öÎÒÏëÒªµÄelementµÄÖµ
xml Ϊ£º
<Discover xmlns="urn:schemas-microsoft-com:xml-analysis">
<RequestType>DISCOVER_XML_ME ......
ÎÒÏÖÔÚÐèÒªÓÃschemaÀ´ÑéÖ¤Ò»¸öXMLÎļþ£¬µ«ÊÇÈ´·ÖÁ˼¸¸öXSDÎļþ£¬ÆäÖÐÓÐÒ»¸öÖ÷XSDÎļþ£¬ÓÃ#Include°üº¬ÁËÆäËûµÄXSDÎļþ¡£ÎÒÔÚXMLÎļþÖÐÖ®ÒýÓÃÖ÷XSDÎļþ£¬µ«ÊDz»³É¹¦£¬ÇëÎÊÎÒÊDz»ÊÇҪȫ²¿ÒýÓ㬻¹ÊÇÆäËûÎÊÌ⣿Èç¹ûÈ«²¿ ......