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

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

      • <bdo id='v8jfU'></bdo><ul id='v8jfU'></ul>

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

        如何告訴 lxml.etree.tostring(element) 不要在 python 中編

        How to tell lxml.etree.tostring(element) not to write namespaces in python?(如何告訴 lxml.etree.tostring(element) 不要在 python 中編寫命名空間?)
        <tfoot id='ma7Vg'></tfoot>
          <bdo id='ma7Vg'></bdo><ul id='ma7Vg'></ul>
            <tbody id='ma7Vg'></tbody>
        • <legend id='ma7Vg'><style id='ma7Vg'><dir id='ma7Vg'><q id='ma7Vg'></q></dir></style></legend>

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

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

                  本文介紹了如何告訴 lxml.etree.tostring(element) 不要在 python 中編寫命名空間?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個巨大的 xml 文件 (1 Gig).我想將一些元素(條目)移動到具有相同標題和規范的另一個文件中.

                  假設原始文件包含帶有標簽<to_move>的條目:

                  <?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE some SYSTEM "some.dtd"><一些>...<to_move date="somedate"><child>一些文字</child>......</to_move>...</一些>

                  我使用 lxml.etree.iterparse 來遍歷文件.工作正常.當我找到帶有標簽 <to_move> 的元素時,假設它存儲在變量 element 我做

                  new_file.write(etree.tostring(element))

                  但這會導致

                  <?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE some SYSTEM "some.dtd"><一些>...<to_move xmlns:="some" date="somedate"># <---- 這就是問題所在.我不想要命名空間.<child>一些文字</child>......</to_move>...</一些>

                  所以問題是:如何告訴 etree.tostring() 不要寫 xmlns:="some".這可能嗎?我在 lxml.etree 的 api-documentation 中苦苦掙扎,但找不到令人滿意的答案.

                  這是我為 etree.trostring 找到的:

                  tostring(element_or_tree, encoding=None, method="xml",xml_declaration=無,pretty_print=False,with_tail=True,獨立=無,文檔類型=無,排他=假,with_comments=真)

                  <塊引用>

                  將元素序列化為其 XML 的編碼字符串表示樹.

                  對我來說,tostring() 的每個參數似乎都沒有幫助.有什么建議或更正嗎?

                  解決方案

                  我經常像這樣抓取一個命名空間為它創建一個別名:

                  someXML = lxml.etree.XML(someString)如果 ns 為無:ns = {"m": someXML.tag.split("}")[0][1:]}someid = someXML.xpath('.//m:ImportantThing//m:ID', namespaces=ns)

                  你可以做一些類似的事情來獲取命名空間,以便在使用 tostring 后創建一個正則表達式來清理它.

                  或者你可以清理輸入字符串.找到第一個空格,檢查后面是否有xmlns,如果是,則刪除整個xmlns直到下一個空格,如果沒有則刪除空格.重復直到沒有更多的空格或 xmlns 聲明.但不要超過第一個 >.

                  I have a huge xml file (1 Gig). I want to move some of the elements (entrys) to another file with the same header and specifications.

                  Let's say the original file contains this entry with tag <to_move>:

                  <?xml version="1.0" encoding="ISO-8859-1"?>
                  <!DOCTYPE some SYSTEM "some.dtd">
                  <some>
                  ...
                  <to_move date="somedate">
                      <child>some text</child>
                      ...
                  ...
                  </to_move>
                  ...
                  </some>
                  

                  I use lxml.etree.iterparse to iterate through the file. Works fine. When I find the element with tag <to_move>, let's assume it is stored in the variable element I do

                  new_file.write(etree.tostring(element))
                  

                  But this results in

                  <?xml version="1.0" encoding="ISO-8859-1"?>
                  <!DOCTYPE some SYSTEM "some.dtd">
                  <some>
                  ...
                  <to_move xmlns:="some" date="somedate">  # <---- Here is the problem. I don't want the namespace.
                      <child>some text</child>
                      ...
                  ...
                  </to_move>
                  ...
                  </some>
                  

                  So the question is: How to tell etree.tostring() not to write the xmlns:="some". Is this possible? I struggeled with the api-documentation of lxml.etree, but I couldn't find a satisfying answer.

                  This is what I found for etree.trostring:

                  tostring(element_or_tree, encoding=None, method="xml",
                  xml_declaration=None, pretty_print=False, with_tail=True,
                  standalone=None, doctype=None, exclusive=False, with_comments=True)
                  

                  Serialize an element to an encoded string representation of its XML tree.

                  To me every one of the parameters of tostring() does not seem to help. Any suggestion or corrections?

                  解決方案

                  I often grab a namespace to make an alias for it like this:

                  someXML = lxml.etree.XML(someString)
                  if ns is None:
                        ns = {"m": someXML.tag.split("}")[0][1:]}
                  someid = someXML.xpath('.//m:ImportantThing//m:ID', namespaces=ns)
                  

                  You could do something similar to grab the namespace in order to make a regex that will clean it up after using tostring.

                  Or you could clean up the input string. Find the first space, check if it is followed by xmlns, if yes, delete the whole xmlns bit up to the next space, if no delete the space. Repeat until there are no more spaces or xmlns declarations. But don't go past the first >.

                  這篇關于如何告訴 lxml.etree.tostring(element) 不要在 python 中編寫命名空間?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 包)
                  <i id='3EoN0'><tr id='3EoN0'><dt id='3EoN0'><q id='3EoN0'><span id='3EoN0'><b id='3EoN0'><form id='3EoN0'><ins id='3EoN0'></ins><ul id='3EoN0'></ul><sub id='3EoN0'></sub></form><legend id='3EoN0'></legend><bdo id='3EoN0'><pre id='3EoN0'><center id='3EoN0'></center></pre></bdo></b><th id='3EoN0'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='3EoN0'><tfoot id='3EoN0'></tfoot><dl id='3EoN0'><fieldset id='3EoN0'></fieldset></dl></div>
                    <bdo id='3EoN0'></bdo><ul id='3EoN0'></ul>
                      <tfoot id='3EoN0'></tfoot>

                        • <legend id='3EoN0'><style id='3EoN0'><dir id='3EoN0'><q id='3EoN0'></q></dir></style></legend>

                              <tbody id='3EoN0'></tbody>

                            <small id='3EoN0'></small><noframes id='3EoN0'>

                            主站蜘蛛池模板: 国产永久精品 | 国产理论视频 | 亚洲综合五月 | 在线日韩一区 | 亚洲伊人影院 | 亚洲免费在线视频 | 国产精品手机在线 | 日韩三级在线播放 | 亚洲国产欧美日韩在线 | 天天色天天爱 | 五月天婷婷视频 | 性色av一区| 国产91av视频 | 一级片在线视频 | 狠狠狠干| 国产免费观看视频 | 国产福利91精品一区二区三区 | 97久久精品人人澡人人爽 | 美女无遮挡网站 | 久久草视频 | 欧美精品久久久久久久 | 黄色一级片免费 | 天天干夜夜操 | 亚洲成人毛片 | 欧美午夜精品久久久久免费视 | 欧美9999| 成人在线一区二区 | 成年人免费在线观看 | 能看毛片的网站 | 天天草天天草 | 久久精品久久久久 | 国产日韩久久 | 成人精品一区二区三区 | 四虎欧美| 色多多视频在线观看 | 日韩欧美精品一区二区 | 国产又色又爽又黄又免费 | 成人免费看片' | 亚洲一区二区久久 | 久久日韩精品 | 韩日一级片 |