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

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

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

          <bdo id='3meQr'></bdo><ul id='3meQr'></ul>

        lxml:將命名空間添加到輸入文件

        lxml: add namespace to input file(lxml:將命名空間添加到輸入文件)
        1. <tfoot id='JvF7q'></tfoot>

                <bdo id='JvF7q'></bdo><ul id='JvF7q'></ul>
                • <legend id='JvF7q'><style id='JvF7q'><dir id='JvF7q'><q id='JvF7q'></q></dir></style></legend>

                    <tbody id='JvF7q'></tbody>

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

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

                • 本文介紹了lxml:將命名空間添加到輸入文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在解析由外部 程序 生成的 xml 文件.然后我想使用我自己的命名空間向這個文件添加自定義注釋.我的輸入如下所示:

                  I am parsing an xml file generated by an external program. I would then like to add custom annotations to this file, using my own namespace. My input looks as below:

                  <sbml xmlns="http://www.sbml.org/sbml/level2/version4" xmlns:celldesigner="http://www.sbml.org/2001/ns/celldesigner" level="2" version="4">
                    <model metaid="untitled" id="untitled">
                      <annotation>...</annotation>
                      <listOfUnitDefinitions>...</listOfUnitDefinitions>
                      <listOfCompartments>...</listOfCompartments>
                      <listOfSpecies>
                        <species metaid="s1" id="s1" name="GenA" compartment="default" initialAmount="0">
                          <annotation>
                            <celldesigner:extension>...</celldesigner:extension>
                          </annotation>
                        </species>
                        <species metaid="s2" id="s2" name="s2" compartment="default" initialAmount="0">
                          <annotation>
                             <celldesigner:extension>...</celldesigner:extension>
                          </annotation>
                        </species>
                      </listOfSpecies>
                      <listOfReactions>...</listOfReactions>
                    </model>
                  </sbml>
                  

                  問題是lxml只在使用時聲明命名空間,這意味著聲明重復了很多次,就像這樣(簡化):

                  The issue being that lxml only declares namespaces when they are used, which means the declaration is repeated many times, like so (simplified):

                  <sbml xmlns="namespace" xmlns:celldesigner="morenamespace" level="2" version="4">
                    <listOfSpecies>
                      <species>
                        <kjw:test xmlns:kjw="http://this.is.some/custom_namespace"/>
                        <celldesigner:data>Some important data which must be kept</celldesigner:data>
                      </species>
                      <species>
                        <kjw:test xmlns:kjw="http://this.is.some/custom_namespace"/>
                      </species>
                      ....
                    </listOfSpecies>
                  </sbml>
                  

                  是否可以強制 lxml 在父元素中僅寫入一次此聲明,例如 sbmllistOfSpecies?還是有充分的理由不這樣做?我想要的結果是:

                  Is it possible to force lxml to write this declaration only once in a parent element, such as sbml or listOfSpecies? Or is there a good reason not to do so? The result I want would be:

                  <sbml xmlns="namespace" xmlns:celldesigner="morenamespace" level="2" version="4"  xmlns:kjw="http://this.is.some/custom_namespace">
                    <listOfSpecies>
                      <species>
                        <kjw:test/>
                        <celldesigner:data>Some important data which must be kept</celldesigner:data>
                      </species>
                      <species>
                        <kjw:test/>
                      </species>
                      ....
                    </listOfSpecies>
                  </sbml>
                  

                  重要的問題是必須保留從文件中讀取的現有數據,所以我不能只創建一個新的根元素(我認為?).

                  The important problem is that the existing data which is read from a file must be kept, so I cannot just make a new root element (I think?).

                  下面附上代碼.

                  def annotateSbml(sbml_input):
                    from lxml import etree
                  
                    checkSbml(sbml_input) # Makes sure the input is valid sbml/xml.
                  
                    ns = "http://this.is.some/custom_namespace"
                    etree.register_namespace('kjw', ns)
                  
                    sbml_doc = etree.ElementTree()
                    root = sbml_doc.parse(sbml_input, etree.XMLParser(remove_blank_text=True))
                    nsmap = root.nsmap
                    nsmap['sbml'] = nsmap[None] # Makes code more readable, but seems ugly. Any alternatives to this?
                    nsmap['kjw'] = ns
                    ns = '{' + ns + '}'
                    sbmlns = '{' + nsmap['sbml'] + '}'
                  
                    for species in root.findall('sbml:model/sbml:listOfSpecies/sbml:species', nsmap):
                      species.append(etree.Element(ns + 'test'))
                  
                    sbml_doc.write("test.sbml.xml", pretty_print=True, xml_declaration=True)
                  
                    return
                  

                  推薦答案

                  lxml中無法修改節點的命名空間映射.請參閱此開放票,該票具有此功能作為愿望清單項目.

                  Modifying the namespace mapping of a node is not possible in lxml. See this open ticket that has this feature as a wishlist item.

                  它源自 這個線程lxml 郵件列表,其中 替代根節點的解決方法 是作為替代方案給出.但是替換根節點存在一些問題:請參閱上面的票證.

                  It originated from this thread on the lxml mailing list, where a workaround replacing the root node is given as an alternative. There are some issues with replacing the root node though: see the ticket above.

                  為了完整起見,我將建議的根替換解決方法代碼放在這里:

                  I'll put the suggested root replacement workaround code here for completeness:

                  >>> DOC = """<sbml xmlns="http://www.sbml.org/sbml/level2/version4" xmlns:celldesigner="http://www.sbml.org/2001/ns/celldesigner" level="2" version="4">
                  ...   <model metaid="untitled" id="untitled">
                  ...     <annotation>...</annotation>
                  ...     <listOfUnitDefinitions>...</listOfUnitDefinitions>
                  ...     <listOfCompartments>...</listOfCompartments>
                  ...     <listOfSpecies>
                  ...       <species metaid="s1" id="s1" name="GenA" compartment="default" initialAmount="0">
                  ...         <annotation>
                  ...           <celldesigner:extension>...</celldesigner:extension>
                  ...         </annotation>
                  ...       </species>
                  ...       <species metaid="s2" id="s2" name="s2" compartment="default" initialAmount="0">
                  ...         <annotation>
                  ...            <celldesigner:extension>...</celldesigner:extension>
                  ...         </annotation>
                  ...       </species>
                  ...     </listOfSpecies>
                  ...     <listOfReactions>...</listOfReactions>
                  ...   </model>
                  ... </sbml>"""
                  >>> 
                  >>> from lxml import etree
                  >>> from StringIO import StringIO
                  >>> NS = "http://this.is.some/custom_namespace"
                  >>> tree = etree.ElementTree(element=None, file=StringIO(DOC))
                  >>> root = tree.getroot()
                  >>> nsmap = root.nsmap
                  >>> nsmap['kjw'] = NS
                  >>> new_root = etree.Element(root.tag, nsmap=nsmap)
                  >>> new_root[:] = root[:]
                  >>> new_root.append(etree.Element('{%s}%s' % (NS, 'test')))
                  >>> new_root.append(etree.Element('{%s}%s' % (NS, 'test')))
                  
                  >>> print etree.tostring(new_root, pretty_print=True)
                  <sbml xmlns:celldesigner="http://www.sbml.org/2001/ns/celldesigner" xmlns:kjw="http://this.is.some/custom_namespace" xmlns="http://www.sbml.org/sbml/level2/version4"><model metaid="untitled" id="untitled">
                      <annotation>...</annotation>
                      <listOfUnitDefinitions>...</listOfUnitDefinitions>
                      <listOfCompartments>...</listOfCompartments>
                      <listOfSpecies>
                        <species metaid="s1" id="s1" name="GenA" compartment="default" initialAmount="0">
                          <annotation>
                            <celldesigner:extension>...</celldesigner:extension>
                          </annotation>
                        </species>
                        <species metaid="s2" id="s2" name="s2" compartment="default" initialAmount="0">
                          <annotation>
                             <celldesigner:extension>...</celldesigner:extension>
                          </annotation>
                        </species>
                      </listOfSpecies>
                      <listOfReactions>...</listOfReactions>
                    </model>
                  <kjw:test/><kjw:test/></sbml>
                  

                  這篇關于lxml:將命名空間添加到輸入文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 包)
                    <bdo id='4jMVZ'></bdo><ul id='4jMVZ'></ul>
                  • <legend id='4jMVZ'><style id='4jMVZ'><dir id='4jMVZ'><q id='4jMVZ'></q></dir></style></legend>
                    <tfoot id='4jMVZ'></tfoot>

                    <small id='4jMVZ'></small><noframes id='4jMVZ'>

                          <tbody id='4jMVZ'></tbody>

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

                            主站蜘蛛池模板: 伊人久久免费视频 | 玖玖色在线视频 | 亚洲国产成人精品久久 | 欧美性受 | 欧美性网 | 国产一区二区在线免费 | 最新91在线| 午夜久久久 | 精品久久视频 | 欧美成人激情 | 91成人在线视频 | 国产精品99久久久久久宅男 | 久久久精品高清 | 精品一区二区三区中文字幕 | 午夜久久久久久久久久一区二区 | 国产线视频精品免费观看视频 | 一区二区三区四区五区在线视频 | 一级毛片网 | 日韩视频精品在线 | h漫在线观看 | 国产成人精品一区二区三 | 女同videos另类| 精品久草 | 特级生活片 | 成人免费看片 | 成人av网站在线观看 | 欧美日韩一区二区三区在线观看 | 成人精品国产 | 日韩国产中文字幕 | 国产高清在线观看 | 污视频免费在线观看 | 日韩高清中文字幕 | 久久精品久久久 | 免费视频一区二区 | 日本在线免费看最新的电影 | 野狼在线社区2017入口 | 一级无毛片| 欧美日韩免费一区二区三区 | 九九热免费在线观看 | 久久久久成人精品亚洲国产 | 国产精品精品 |