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

熱點內容
androideclipse32 瀏覽:125
商用壓縮機承受溫度 瀏覽:48
健身房壓縮衣 瀏覽:976
單片機太陽光追蹤系統所需材料 瀏覽:356
比澤爾壓縮機型號規則 瀏覽:85
華興數控切斷編程 瀏覽:789
西安離心壓縮機 瀏覽:545
程序員需要優盤嗎 瀏覽:879
西藏掌上社保app在哪裡下載 瀏覽:599
怎麼讓伺服器固定 瀏覽:65
計數器定時器編程 瀏覽:13
程序員網上投資平台 瀏覽:878
用shell編程計算1加到100 瀏覽:233
外包公司的程序員一天寫多少代碼 瀏覽:532
蘋果手機主屏幕app如何移動 瀏覽:567
伺服器怎麼連接遠程密碼 瀏覽:431
linux娛樂命令 瀏覽:368
單片機數碼管循環顯示9到0 瀏覽:494
程序員懟代碼思路 瀏覽:327
新能源碼磚機產品介紹 瀏覽:37