久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 lxml 中解析 XML 時如何不加載注釋

How to not load the comments while parsing XML in lxml(在 lxml 中解析 XML 時如何不加載注釋)
本文介紹了在 lxml 中解析 XML 時如何不加載注釋的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我嘗試像這樣使用 lxml 在 Python 中解析 XML 文件:

I try to parse XML file in Python using lxml like this:

objectify.parse(xmlPath, parserWithSchema)

但 XML 文件可能在奇怪的地方包含注釋:

but XML file may contains comments in strange places:

<root>
    <text>Sam<!--comment-->ple text</text>
    <!--comment-->
    <float>1.2<!--comment-->3456</float>
</root>

是一種在解析前不加載或刪除評論的方法嗎?

It is a way to not load or delete comments before parsing?

推薦答案

在解析器上設置 remove_comments=True (文檔):

Set remove_comments=True on the parser (documentation):

from lxml import etree, objectify

parser = etree.XMLParser(remove_comments=True)
tree = objectify.parse(xmlPath, parser=parser)

或者,使用 makeparser() 方法:

parser = objectify.makeparser(remove_comments=True)
tree = objectify.parse(xmlPath, parser=parser)

希望對您有所幫助.

這篇關于在 lxml 中解析 XML 時如何不加載注釋的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件時出現問題)
Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按屬性查找所有節點)
Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 響應并將元素值存儲在變量中?)
How to get XML tag value in Python(如何在 Python 中獲取 XML 標記值)
How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正確解析 utf-8 xml?)
Parse XML from URL into python object(將 XML 從 URL 解析為 python 對象)
主站蜘蛛池模板: 超碰精品在线观看 | 一级毛片在线播放 | 一区二区中文字幕 | 日韩在线免费 | 日韩第一夜 | 亚洲福利在线观看 | 欧美a v在线 | 青青久草 | 日韩国产中文字幕 | 亚洲国产视频一区二区 | 成人福利在线观看 | 啪视频在线 | 日本三级电影在线看 | 国产精品区二区三区日本 | 成年人在线 | 影音先锋亚洲资源 | 97色在线视频 | 成人影院在线视频 | 另类专区成人 | 国产精品亚洲一区二区三区在线 | 爱综合 | 成人精品一区 | 久久最新网址 | 欧美精品一二三 | 2022精品国偷自产免费观看 | 99精品视频一区二区三区 | 99精品欧美一区二区蜜桃免费 | 久久久国产精品视频 | 中文字幕欧美日韩一区 | 91精品国产综合久久福利软件 | 91在线区 | 爱爱爱av | 欧美激情综合五月色丁香小说 | 特黄av| 日本 欧美 国产 | 亚洲成人国产精品 | 日韩手机在线看片 | 午夜精品一区二区三区在线视频 | 亚洲视频免费观看 | 日韩在线xx| 精品久久久精品 |