導航:首頁 > 編程語言 > pythonxmlstring

pythonxmlstring

發布時間:2025-02-01 00:06:08

1. 比較兩個xml節點的異同 python

1. 你好明物-兩個或lxml的樹。
2. 如果你把一個DOM方法,你可以根據需要去穿越兩棵樹的節點(節點類型,文槐碼本,屬性)。 遞歸的解決方案將是最優雅的-只是短路一次一對節點不是「等於」或一旦檢測到葉一棵樹,當它在另一個分支,等等。
parser = etree.XMLParser(remove_blank_text=True)
xml1 = etree.fromstring(xml_string1, parser)
xml2 = etree.fromstring(xml_string2, parser)
print "xml1 == xml2: " + str(xml1 == xml2)
友液ppxml1 = etree.tostring(xml1, pretty_print=True)
ppxml2 = etree.tostring(xml2, pretty_print=True)
print "pretty(xml1) == pretty(xml2): " + str(ppxml1 == ppxml2)
xml_string_io1 = StringIO()
xml1.getroottree().write_c14n(xml_string_io1)
cxml1 = xml_string_io1.getvalue()
xml_string_io2 = StringIO()
xml2.getroottree().write_c14n(xml_string_io2)
cxml2 = xml_string_io2.getvalue()
print "canonicalize(xml1) == canonicalize(xml2): " + str(cxml1 == cxml2)

2. python 如何把xml文件轉化成string

你說的不是xml文件吧,是xml對象轉化成string吧。

你可以使用toxml()這個方法。

Node.toxml([encoding])
"""
.
Withnoargument,,andtheresultis

document.-8islikely
incorrect,sinceUTF-8isthedefaultencodingofXML.
Withanexplicitencoding[1]argument,theresultisabytestringinthe
specifiedencoding..To
,the
「utf-8」.
Changedinversion2.3:;seewritexml().
"""

如果解決了您的問題請採納!
如果未解決請繼續追問

閱讀全文

與pythonxmlstring相關的資料

熱點內容
相片如何用電解壓 瀏覽:905
碩士程序員去學校當老師 瀏覽:120
pythonstr提取到字典 瀏覽:818
程序員那麼可愛有人看上陸漓了 瀏覽:876
php正則提取圖片 瀏覽:103
pythonlinuxdjango 瀏覽:562
php中文返回亂碼 瀏覽:89
宿舍裝的電信怎麼加密 瀏覽:745
為什麼壓縮文件解壓後變少了 瀏覽:426
現在安卓充電器普遍是什麼型號 瀏覽:714
9日均線36均線主圖指標源碼 瀏覽:349
程序員阿里文化完整版 瀏覽:98
早間新聞在哪個app上面可以看 瀏覽:954
工作啦app注冊的信息怎麼刪去 瀏覽:378
滾動轉子式製冷壓縮機 瀏覽:873
美國編程用什麼軟體 瀏覽:571
圖片加密防盜用 瀏覽:616
dbscan演算法python源碼 瀏覽:849
固態硬碟文件夾刪不掉 瀏覽:717
陽泉工會app怎麼培訓報名 瀏覽:669