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

熱點內容
程序員入職拼多多 瀏覽:119
pc如何訪問伺服器配置 瀏覽:76
pdfpower 瀏覽:42
linux系統運行級別 瀏覽:229
android下載文件demo 瀏覽:949
人體解剖圖pdf 瀏覽:823
php拋出異常處理 瀏覽:502
java字元串轉為對象 瀏覽:617
西貝爾壓縮機怎樣 瀏覽:616
phpzookeeper擴展 瀏覽:587
vue壓縮後的js可以反編嗎 瀏覽:854
javachar數組賦值 瀏覽:103
自動畫頸線指標源碼 瀏覽:72
訪問共享文件夾錯誤代碼 瀏覽:504
代號pdf 瀏覽:19
java編碼規范pdf 瀏覽:146
linuxshellread 瀏覽:226
st單片機命名 瀏覽:861
華為路由器彈出提示命令 瀏覽:887
伺服器地址失效 瀏覽:642