導航:首頁 > 編程語言 > 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相關的資料

熱點內容
穿雲伺服器 瀏覽:394
單片機核心電壓表 瀏覽:151
最強大逃頂通達信指標源碼 瀏覽:441
java程序員面試寶典歐立奇 瀏覽:457
cad命令不要跟著游標 瀏覽:200
騰訊軟體伺服器是什麼 瀏覽:894
高中單片機 瀏覽:347
正則命令 瀏覽:341
javawin10配置環境變數 瀏覽:564
梁全長箍筋加密怎麼設置 瀏覽:403
蘋果appstore怎麼填 瀏覽:688
radiogroupandroid 瀏覽:152
微信加密手機店能破解嗎 瀏覽:952
如何更換win7補丁伺服器地址 瀏覽:702
如何舉報dota2伺服器 瀏覽:584
蘋果怎麼打鏈接微信文件夾 瀏覽:366
阿拉德之路怎麼蘋果跟安卓一起玩 瀏覽:241
主力排序選股源碼 瀏覽:149
android無法生成apk文件 瀏覽:505
如何開一個掛網頁的伺服器 瀏覽:538