How to set element's id in Python's xml.dom.minidom?

后端 未结 2 495
無奈伤痛
無奈伤痛 2020-12-30 17:35

How to? Created a document and an element:

import xml.dom.minidom as d
a=d.Document()
b=a.createElement(\'test\')

setIdAttribute doesn\'t w

2条回答
  •  再見小時候
    2020-12-30 17:50

    Adding the name of the id attribute to the DTD should help. For example, if you want every to set the id as the id attribute for all

    elements, you can set up your DTD as follows:

    ]>

    This is a working example:

    >>> from xml.dom.minidom import parse, parseString                              
    >>> data=']>
    FOO word
    BAR word
    ' >>> x=parseString(data) >>> x.getElementById('foo') >>> x.getElementById('foo').toxml() u'
    FOO word
    '

提交回复
热议问题