本文整理汇总了Python中xml.dom.minidom.Element类的典型用法代码示例。如果您正苦于以下问题:Python Element类的具体用法?Python Element怎么用?Python Element使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Element类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, name, subtag_name, data, name_att='name'):
Element.__init__(self, name)
self.__data_dict__ = {}
for key, value in data.items():
self.__data_dict__[key] = TextElement(subtag_name, value)
self.__data_dict__[key].setAttribute('name', key)
self.appendChild(self.__data_dict__[key])
示例2: __init__
def __init__(self, apt_id, uri, dist, sections, local_path):
Element.__init__(self, 'aptsource')
self.setAttribute('apt_id', apt_id)
self.setAttribute('uri', uri)
self.setAttribute('dist', dist)
self.setAttribute('sections', sections)
self.setAttribute('local_path', local_path)
示例3: xml_encode
def xml_encode(self, text):
from xml.dom.minidom import Text, Element
t = Text()
t.data = text
e = Element('x')
e.appendChild(t)
return e.toxml()[3:-4]
示例4: __init__
def __init__(self, suite, nonus=False, updates=False, local=False, common=False):
Element.__init__(self, "suite")
self.setAttribute("name", suite)
self.setAttribute("nonus", nonus)
self.setAttribute("updates", updates)
self.setAttribute("local", local)
self.setAttribute("common", common)
示例5: __init__
def __init__(self, conn, machines=None):
raise RuntimeError , "ClientMachineDatabaseElement isn't working"
Element.__init__(self, 'machine_database')
self.conn = conn
if machines is not None:
self.machines = MachinesElement(conn, machines)
self.appendChild(self.machines)
示例6: __init__
def __init__(self, conn, path='/'):
Element.__init__(self, 'paelladatabase')
self.conn = conn
self.stmt = StatementCursor(self.conn)
self._profile_traits_ = ProfileTrait(self.conn)
self.path = path
self.aptsources = AptSourceListElement()
self.appendChild(self.aptsources)
if 'apt_sources' in self.stmt.tables():
for row in self.stmt.select(table='apt_sources', order=['apt_id']):
element = AptSourceElement(row.apt_id, row.uri, row.dist, row.sections,
row.local_path)
self.aptsources.appendChild(element)
self.suites = SuitesElement()
self.appendChild(self.suites)
for row in self._suite_rows():
args = map(str, [row.suite, row.nonus, row.updates, row.local, row.common])
element = SuiteElement(*args)
for suiteapt in self.stmt.select(table='suite_apt_sources', order=['ord'],
clause=Eq('suite', row.suite)):
element.appendChild(SuiteAptElement(row.suite,
suiteapt.apt_id, str(suiteapt.ord)))
self.suites.appendChild(element)
else:
print 'WARNING, apt_sources table does not exist, backing up anyway'
self.profiles = PaellaProfiles(self.conn)
self.family = Family(self.conn)
suites = [x.suite for x in self._suite_rows()]
for suite in suites:
self.appendChild(TraitsElement(self.conn, suite))
示例7: __init__
def __init__(self, name, type, value, is_array=None,
array_size=None, qualifier_scopes={},
overridable=None, tosubclass=None,
toinstance=None, translatable=None):
Element.__init__(self, 'QUALIFIER.DECLARATION')
self.setName(name)
self.setAttribute('TYPE', type)
if is_array is not None:
self.setOptionalAttribute('ISARRAY', str(is_array).lower())
if array_size is not None:
self.setAttribute('ARRAYSIZE', str(array_size))
if overridable is not None:
self.setAttribute('OVERRIDABLE', str(overridable).lower())
if tosubclass is not None:
self.setAttribute('TOSUBCLASS', str(tosubclass).lower())
if toinstance is not None:
self.setAttribute('TOINSTANCE', str(toinstance).lower())
if translatable is not None:
self.setAttribute('TRANSLATABLE', str(translatable).lower())
if qualifier_scopes:
scope = SCOPE(qualifier_scopes)
self.appendOptionalChild(scope)
if value is not None:
if is_array:
xval = VALUE_ARRAY(value)
else:
xval = VALUE(value)
self.appendOptionalChild(xval)
示例8: _add_lang_to_html
def _add_lang_to_html(htmltext, lang):
'''
Take a piece of HTML and add an xml:lang attribute to it.
'''
if lang == 'und':
return htmltext
parser = html5lib.HTMLParser(
tree=html5lib.treebuilders.getTreeBuilder("dom")
)
html = parser.parseFragment(htmltext)
html.normalize()
if len(html.childNodes) == 0:
return '<div xml:lang="%s"></div>' % lang
elif len(html.childNodes) == 1:
node = html.firstChild
if node.nodeType == Node.TEXT_NODE:
div = Element('div')
div.ownerDocument = html
div.setAttribute('xml:lang', lang)
div.childNodes = [node]
html.childNodes = [div]
else:
node.setAttribute('xml:lang', lang)
else:
#add a single encompassing div
div = Element('div')
div.ownerDocument = html
div.setAttribute('xml:lang', lang)
div.childNodes = html.childNodes
html.childNodes = [div]
return html.toxml()
示例9: __init__
def __init__(self, name, reference_class=None, array_size=None, qualifiers=[]):
Element.__init__(self, "PARAMETER.REFARRAY")
self.setName(name)
self.setOptionalAttribute("REFERENCECLASS", reference_class)
if array_size is not None:
self.setAttribute("ARRAYSIZE", str(array_size))
self.appendChildren(qualifiers)
示例10: get
def get(self, *args):
self.response.headers['Content-Type'] = "application/rss+xml"
items = self.getItems(*args)
itemElems = []
for item in items:
itemElem = Element("item")
self._appendElementWithTextNode(itemElem, "title", item.title)
self._appendElementWithTextNode(itemElem, "link", item.link)
self._appendElementWithTextNode(itemElem, "description", item.description)
self._appendElementWithTextNode(itemElem, "guid", item.link)
if item.subPlaceFeedLink:
self._appendElementWithTextNode(itemElem, "sharkattackdata:subPlaceFeedLink", item.subPlaceFeedLink)
if item.attackFeedLink:
self._appendElementWithTextNode(itemElem, "sharkattackdata:attackFeedLink", item.attackFeedLink)
itemElems.append(itemElem)
# Need to make channel element after the generator returned by getItems has been iterated.
channelElem = Element("channel")
self._appendElementWithTextNode(channelElem, "title", self._feedTitle)
self._appendElementWithTextNode(channelElem, "link", self._feedLink)
self._appendElementWithTextNode(channelElem, "description", self._feedDescription)
for itemElem in itemElems:
channelElem.appendChild(itemElem)
responseText = """<?xml version="1.0"?>
<rss version="2.0" xmlns:sharkattackdata="http://sharkattackdata.com/rss/modules/1.0/">
%s
</rss>
""" % (channelElem.toprettyxml())
self.response.out.write(responseText)
示例11: __init__
def __init__(self, ownerDocument, name=""):
Element.__init__(self, TAG_CATEGORY)
self.name = name
self.ownerDocument = ownerDocument
self._items = []
self.setAttribute("name", self.name)
示例12: node2xml
def node2xml(node):
"""Takes in a node object and returns an XML object for that node"""
ele = Element("node")
for k, v in node.attrs.items():
ele.setAttribute(k, v)
for k, v in node.tags.items():
ele.appendChild(tag2xml(k, v))
return ele
示例13: _getElementForMappingEntry
def _getElementForMappingEntry(entry, mappingStyle):
e = Element(mappingStyle)
for k, v in entry.items():
# ignore empty, None or compiled regexp items into output
if not v or (k == "path-match-expr"):
continue
e.setAttribute(k, str(v))
return e
示例14: __init__
def __init__(self, mnt_name, mnt_point, fstype, mnt_opts, dump, pass_):
Element.__init__(self, "mount")
self.setAttribute("mnt_name", mnt_name)
self.setAttribute("mnt_point", mnt_point)
self.setAttribute("fstype", fstype)
self.setAttribute("mnt_opts", mnt_opts)
self.setAttribute("dump", dump)
self.setAttribute("pass", pass_)
示例15: set_scripts
def set_scripts(self):
self.scripts = [x.script for x in self.traitscripts.scripts(self.name)]
while self.scripts_element.hasChildNodes():
del self.scripts_element.childNodes[0]
for script in self.scripts:
element = Element('script')
element.setAttribute('name', script)
self.scripts_element.appendChild(element)