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

    <bdo id='FSByy'></bdo><ul id='FSByy'></ul>

  • <small id='FSByy'></small><noframes id='FSByy'>

    <i id='FSByy'><tr id='FSByy'><dt id='FSByy'><q id='FSByy'><span id='FSByy'><b id='FSByy'><form id='FSByy'><ins id='FSByy'></ins><ul id='FSByy'></ul><sub id='FSByy'></sub></form><legend id='FSByy'></legend><bdo id='FSByy'><pre id='FSByy'><center id='FSByy'></center></pre></bdo></b><th id='FSByy'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='FSByy'><tfoot id='FSByy'></tfoot><dl id='FSByy'><fieldset id='FSByy'></fieldset></dl></div>

      <legend id='FSByy'><style id='FSByy'><dir id='FSByy'><q id='FSByy'></q></dir></style></legend>

        <tfoot id='FSByy'></tfoot>

        使用 lxml 從 python 中的 xml 中刪除命名空間和前綴

        Remove namespace and prefix from xml in python using lxml(使用 lxml 從 python 中的 xml 中刪除命名空間和前綴)
      1. <legend id='XGZoY'><style id='XGZoY'><dir id='XGZoY'><q id='XGZoY'></q></dir></style></legend>

        <tfoot id='XGZoY'></tfoot>

        <small id='XGZoY'></small><noframes id='XGZoY'>

          • <bdo id='XGZoY'></bdo><ul id='XGZoY'></ul>
            <i id='XGZoY'><tr id='XGZoY'><dt id='XGZoY'><q id='XGZoY'><span id='XGZoY'><b id='XGZoY'><form id='XGZoY'><ins id='XGZoY'></ins><ul id='XGZoY'></ul><sub id='XGZoY'></sub></form><legend id='XGZoY'></legend><bdo id='XGZoY'><pre id='XGZoY'><center id='XGZoY'></center></pre></bdo></b><th id='XGZoY'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='XGZoY'><tfoot id='XGZoY'></tfoot><dl id='XGZoY'><fieldset id='XGZoY'></fieldset></dl></div>
                <tbody id='XGZoY'></tbody>

                • 本文介紹了使用 lxml 從 python 中的 xml 中刪除命名空間和前綴的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我需要打開一個 xml 文件并對其進行一些更改,其中一項更改是刪除名稱空間和前綴,然后保存到另一個文件.這是xml:

                  I have an xml file I need to open and make some changes to, one of those changes is to remove the namespace and prefix and then save to another file. Here is the xml:

                  <?xml version='1.0' encoding='UTF-8'?>
                  <package xmlns="http://apple.com/itunes/importer">
                    <provider>some data</provider>
                    <language>en-GB</language>
                  </package>
                  

                  我可以進行我需要的其他更改,但不知道如何刪除命名空間和前綴.這是我需要的 reusklt xml:

                  I can make the other changes I need, but can't find out how to remove the namespace and prefix. This is the reusklt xml I need:

                  <?xml version='1.0' encoding='UTF-8'?>
                  <package>
                    <provider>some data</provider>
                    <language>en-GB</language>
                  </package>
                  

                  這是我的腳本,它將打開并解析 xml 并保存它:

                  And here is my script which will open and parse the xml and save it:

                  metadata = '/Users/user1/Desktop/Python/metadata.xml'
                  from lxml import etree
                  parser = etree.XMLParser(remove_blank_text=True)
                  open(metadata)
                  tree = etree.parse(metadata, parser)
                  root = tree.getroot()
                  tree.write('/Users/user1/Desktop/Python/done.xml', pretty_print = True, xml_declaration = True, encoding = 'UTF-8')
                  

                  那么我將如何在腳本中添加代碼來刪除命名空間和前綴?

                  So how would I add code in my script which will remove the namespace and prefix?

                  推薦答案

                  按照 Uku Loskit 的建議替換標簽.除此之外,使用 lxml.objectify.deannotate.

                  Replace tag as Uku Loskit suggests. In addition to that, use lxml.objectify.deannotate.

                  from lxml import etree, objectify
                  
                  metadata = '/Users/user1/Desktop/Python/metadata.xml'
                  parser = etree.XMLParser(remove_blank_text=True)
                  tree = etree.parse(metadata, parser)
                  root = tree.getroot()
                  
                  ####    
                  for elem in root.getiterator():
                      if not hasattr(elem.tag, 'find'): continue  # (1)
                      i = elem.tag.find('}')
                      if i >= 0:
                          elem.tag = elem.tag[i+1:]
                  objectify.deannotate(root, cleanup_namespaces=True)
                  ####
                  
                  tree.write('/Users/user1/Desktop/Python/done.xml',
                             pretty_print=True, xml_declaration=True, encoding='UTF-8')
                  

                  更新

                  Comment 等一些標簽在訪問 tag 屬性時會返回一個函數.為此增加了一名警衛.(1)

                  Some tags like Comment return a function when accessing tag attribute. added a guard for that. (1)

                  這篇關于使用 lxml 從 python 中的 xml 中刪除命名空間和前綴的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)
                  Configuring Python to use additional locations for site-packages(配置 Python 以使用站點包的其他位置)
                  How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造python包)
                  Install python packages on OpenShift(在 OpenShift 上安裝 python 包)
                  How to refresh sys.path?(如何刷新 sys.path?)
                  Distribute a Python package with a compiled dynamic shared library(分發帶有已編譯動態共享庫的 Python 包)
                • <tfoot id='8a2yz'></tfoot>

                    <i id='8a2yz'><tr id='8a2yz'><dt id='8a2yz'><q id='8a2yz'><span id='8a2yz'><b id='8a2yz'><form id='8a2yz'><ins id='8a2yz'></ins><ul id='8a2yz'></ul><sub id='8a2yz'></sub></form><legend id='8a2yz'></legend><bdo id='8a2yz'><pre id='8a2yz'><center id='8a2yz'></center></pre></bdo></b><th id='8a2yz'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='8a2yz'><tfoot id='8a2yz'></tfoot><dl id='8a2yz'><fieldset id='8a2yz'></fieldset></dl></div>
                        <bdo id='8a2yz'></bdo><ul id='8a2yz'></ul>

                        <legend id='8a2yz'><style id='8a2yz'><dir id='8a2yz'><q id='8a2yz'></q></dir></style></legend>

                            <tbody id='8a2yz'></tbody>

                        1. <small id='8a2yz'></small><noframes id='8a2yz'>

                            主站蜘蛛池模板: 亚洲一区二区三区观看 | 亚洲自拍偷拍免费视频 | 黄色91在线| 黄 色 毛片免费 | 黄网免费看 | 久久久久精| 国产精品一二三区 | 给我免费的视频在线观看 | 特黄毛片 | 99re在线视频 | 日韩av一区二区在线观看 | 日韩在线免费视频 | 爱爱视频在线观看 | 久久精品一区二区视频 | av一级一片 | 99精品国产一区二区青青牛奶 | 韩日一区二区 | 黄色一级毛片免费看 | 欧美激情99| 久久成人免费 | 国产在线高清 | 日韩中文在线视频 | 亚洲一区二区三区免费 | 久久精品一区二 | 国产成人免费视频网站高清观看视频 | 欧美午夜一区 | 精品乱码一区二区 | 欧美a区| 久热国产精品视频 | 成人国产精品久久久 | www.国产| 午夜视频免费网站 | av网站免费观看 | 黄色大片观看 | 日韩在线视频一区 | 欧美在线 | 日韩一级精品视频在线观看 | 精品国产一区二区国模嫣然 | 欧日韩在线观看 | 日韩性生活网 | 日韩伦理一区二区 |