当前位置: 首页>>代码示例>>Python>>正文


Python SubElement.tail方法代码示例

本文整理汇总了Python中xml.etree.ElementTree.SubElement.tail方法的典型用法代码示例。如果您正苦于以下问题:Python SubElement.tail方法的具体用法?Python SubElement.tail怎么用?Python SubElement.tail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xml.etree.ElementTree.SubElement的用法示例。


在下文中一共展示了SubElement.tail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: format_name

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import tail [as 别名]
def format_name(parent, name_node, contributor, role, swap=False):
    contributor_node = SubElement(parent, "span")
    contributor_node.set('property', get_property(role))

    if 'given' and 'family' in contributor:

        contributor_node.set('typeOf', 'foaf:Person')

        init_with = name_node.get('initialize-with')
        display_as_sort = contributor.get('display-as-sort')

        if display_as_sort or swap:
            fname = SubElement(contributor_node, 'span')
            fname.set('property', 'foaf:surname')
            fname.text = contributor['family']
            fname.tail = ", " if swap else " "
        
            gname = SubElement(contributor_node, 'span')
            gname.set('property', 'foaf:givenname')

            if init_with:
                if display_as_sort:
                    gname.text = contributor['given']
                else:
                    gname.set('content', contributor['given'])
                    gname.text = initialize(contributor['given'], init_with)
        else:
            gname = SubElement(contributor_node, 'span')
            gname.set('property', 'foaf:givenname')
            if init_with:
                gname.set('content', contributor['given'])
                gname.text = initialize(contributor['given'], init_with)
            else:
                gname.set('content', contributor['given'])
            gname.tail = " "

            fname = SubElement(contributor_node, 'span')
            fname.set('property', 'foaf:surname')
            fname.text = contributor['family']

    elif contributor['name']:
        # we assume we have an organization
        contributor_node.set('typeOf', 'foaf:Organization')
        name = SubElement(contributor_node, 'span')
        name.set('property', 'foaf:name')
        name.text = contributor['name']
    
    return(contributor_node)
开发者ID:bdarcus,项目名称:citeproc-py,代码行数:50,代码来源:citeproc.py

示例2: createEvent

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import tail [as 别名]
		def createEvent(i, time):
			itemElem = SubElement(eventsElem, 'item',
					id=str(baseID + i), type='KeyMatrixState')
			itemElem.tail = '\n'
			stateChangeElem = SubElement(itemElem, 'StateChange')
			timeElem1 = SubElement(stateChangeElem, 'time')
			timeElem2 = SubElement(timeElem1, 'time')
			timeElem2.text = str(time)
			return itemElem
开发者ID:SaifBoras,项目名称:openMSX,代码行数:11,代码来源:txt2omr.py

示例3: set_license

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import tail [as 别名]
    def set_license(self, parent, poa_article):
        self.license = SubElement(parent, "license")

        self.license.set("xlink:href", poa_article.license.href)

        self.license_p = SubElement(self.license, "license-p")
        self.license_p.text = poa_article.license.p1

        ext_link = SubElement(self.license_p, "ext-link")
        ext_link.set("ext-link-type", "uri")
        ext_link.set("xlink:href", poa_article.license.href)
        ext_link.text = poa_article.license.name
        ext_link.tail = poa_article.license.p2
开发者ID:gnott,项目名称:elife-poa-xml-generation,代码行数:15,代码来源:generatePoaXml.py

示例4: mv_toxml

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import tail [as 别名]
    def mv_toxml(self, root=None):
        if root is None:
            cluster = Element('Cluster')
        else:
            cluster = SubElement(root, 'Cluster')
        cluster.text = '\n'
        cluster.tail = "\n"

        name = SubElement(cluster, "Name")
        name.text = self.name
        name.tail = "\n"
        vals = SubElement(cluster, 'NumElts')
        vals.text = str(len(self.mv_attrs))
        vals.tail = "\n"

        # python unifies number types into a single
        # type, so we have to use a separate mapping
        # to find the proper "type" label to wrap
        # the element in.
        for attr in self.mv_attrs:
            lv_type = self.name_to_lv_type[attr]
            typ = SubElement(cluster, lv_type)
            typ.text = "\n"
            typ.tail = "\n"

            name = SubElement(typ, "Name")
            name.text = attr
            name.tail = "\n"
            val = SubElement(typ, "Val")

            if lv_type == 'SGL':
                val.text = "%.5f" % getattr(self, attr)
            else:
                val.text = "%s" % getattr(self, attr)
            val.tail = "\n"

        return cluster
开发者ID:nitetrain8,项目名称:scripts,代码行数:39,代码来源:state.py

示例5: _create_hello_tree_msg

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import tail [as 别名]
    def _create_hello_tree_msg(self, msg, name, reply):
        if isinstance(msg, bytes):
            msg = msg.decode('utf-8', 'strict')

        message = SubElement(reply, "Message")
        # check if object is iterable and not a string
        try:
            iter(msg)
        except TypeError:
            msg = str(msg)

        if isinstance(msg, str):
            message.text = msg
            message.tail = ""
        else:

            # after parsing the message, change the cluster tag to "message".
            self.parse(msg, name, message)
            message = reply[1]
            message.tag = "Message"
            message.text = ""
            message.tail = ""
            cluster = message[0]
            cluster.tail = ""
开发者ID:nitetrain8,项目名称:scripts,代码行数:26,代码来源:util.py

示例6: create_example

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import tail [as 别名]
def create_example():
    top = Element('top')

    comment = Comment('Generated for PyMOTW')
    top.append(comment)

    child = SubElement(top, 'child')
    child.text = 'This child contains text.'

    child_with_tail = SubElement(top, 'child_with_tail')
    child_with_tail.text = 'This child has regular text.'
    child_with_tail.tail = 'And "tail" text.'

    child_with_entity_ref = SubElement(top, 'child_with_entity_ref')
    child_with_entity_ref.text = 'This & that'

    print prettify(top)
开发者ID:vhnuuh,项目名称:pyutil,代码行数:19,代码来源:creating.py

示例7: write_layers

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import tail [as 别名]
 def write_layers(self):
     """Write a layer"""
     for layer in self.map.getLayers():
         cellgrid = layer.getCellGrid()
         attrib = {
             "id": layer.getId(),
             "grid_type": cellgrid.getType(),
             "x_scale": str(cellgrid.getXScale()),
             "y_scale": str(cellgrid.getYScale()),
             "rotation": str(cellgrid.getRotation()),
             "x_offset": str(cellgrid.getXShift()),
             "y_offset": str(cellgrid.getYShift()),
             "pathing": self.pathing_val_to_str(layer.getPathingStrategy()),
             "transparency": str(layer.getLayerTransparency()),
         }
         layer_element = SubElement(self.map_element, "layer", attrib)
         layer_element.text = "\n\t\t"
         layer_element.tail = "\n\n\t"
         self.write_instances(layer_element, layer)
开发者ID:m64,项目名称:PEG,代码行数:21,代码来源:savers.py

示例8: write_instances

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import tail [as 别名]
    def write_instances(self, layer_element, layer):
        """Write out the instances in a layer"""
        instances_element = SubElement(layer_element, "instances")
        instances_element.text = "\n\t\t\t"
        instances_element.tail = "\n\t"
        for inst in layer.getInstances():
            position = inst.getLocationRef().getExactLayerCoordinates()
            attrib = {
                "o": inst.getObject().getId(),
                "x": str(position.x),
                "y": str(position.y),
                "z": str(position.z),
                "r": str(inst.getRotation()),
            }
            namespace = inst.getObject().getNamespace()
            if namespace != self.namespace:
                attrib["ns"] = inst.getObject().getNamespace()
                self.namespace = namespace
            inst_id = inst.getId()
            if inst_id:
                attrib["id"] = inst_id

            # if the object has an instance id, write out saved attributes
            if inst_id is not None and inst_id in loaders.data.objects:
                skip_keys = ["gfx", "xpos", "ypos"]
                for key in loaders.data.objects[inst_id]:
                    # set value if we haven't written the key out yet and key
                    # has a value in our attr stash (loaders.data.objects)
                    if key in skip_keys or key in attrib or key not in loaders.data.objects[inst_id]:
                        continue

                    attrib[key] = str(loaders.data.objects[inst_id][key])

            # the local_loader loader sets object_type as type, we have to
            # correct for that here but really we should fix that there
            if attrib.get("type"):
                attrib["object_type"] = attrib["type"]
                del attrib["type"]

            inst_element = Element("i", attrib)
            inst_element.tail = "\n\t\t\t"
            instances_element.append(inst_element)
开发者ID:m64,项目名称:PEG,代码行数:44,代码来源:savers.py

示例9: Copyright

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import tail [as 别名]
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
#
"""Creating XML documents
"""
#end_pymotw_header

from xml.etree.ElementTree import Element, SubElement, Comment
from ElementTree_pretty import prettify

top = Element('top')

comment = Comment('Generated for PyMOTW')
top.append(comment)

child = SubElement(top, 'child')
child.text = 'This child contains text.'

child_with_tail = SubElement(top, 'child_with_tail')
child_with_tail.text = 'This child has regular text.'
child_with_tail.tail = 'And "tail" text.'

child_with_entity_ref = SubElement(top, 'child_with_entity_ref')
child_with_entity_ref.text = 'This & that'

print prettify(top)
开发者ID:artivee,项目名称:basc,代码行数:30,代码来源:ElementTree_create_pretty.py

示例10: SubElement

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import tail [as 别名]
        c = path.rfind('/')
        if c >= 0:
                path = path[c+1:]

        if letter is None or n[0].upper() != letter:
                letter = n[0].upper()

                h2 = SubElement(body, 'h2')
                h2.text = letter

                ul = SubElement(body, 'ul')
                ul.set('style', 'list-style-type:none')

        li = SubElement(ul, 'li')

        a = SubElement(li, 'a')
        a.set('href', path)
        a.text = n + '(' + section + ')'
        a.tail = ' -- '

        i = SubElement(li, 'i')
        i.text = purpose

hr = SubElement(body, 'hr')

p = SubElement(body, 'p')
p.text = "This index contains %s entries, referring to %i individual manual pages." % (len(index), len(argv)-1)

prettify(html)
stdout.write(tostring(html))
开发者ID:adsr,项目名称:systemd,代码行数:32,代码来源:make-man-index.py

示例11: _create_opf

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import tail [as 别名]
	def _create_opf(self):
		"""
        Create the manifest file. Includes the list of resources, book metadata, and the spine. The manifest
        file is added to the book as ``package.opf``
        """
		# Last step: the manifest file must be created
		# Parse the raw manifest file
		ET.register_namespace('', "http://www.idpf.org/2007/opf")
		opf = ElementTree(ET.fromstring(PACKAGE))
		manifest = opf.findall(".//{http://www.idpf.org/2007/opf}manifest")[0]
		metadata = opf.findall(".//{http://www.idpf.org/2007/opf}metadata")[0]

		# Get the default resources first
		for (href, media_type, item_id, prop) in DEFAULT_FILES:
			item = SubElement(manifest, "{http://www.idpf.org/2007/opf}item")
			item.set("id", item_id.replace('.','-'))
			item.set("href", href)
			item.set("media-type", media_type)
			if prop != "":
				item.set("properties", prop)
			item.tail = "\n    "

		item = SubElement(manifest, "{http://www.idpf.org/2007/opf}item")
		item.set("id", "main")
		item.set("href", "Overview.xhtml")
		item.set("media-type", "application/xhtml+xml")
		if self.document.properties is not None:
			item.set("properties", self.document.properties)
		item.tail = "\n    "

		# Add the additional resources
		for resource_target, media_type in set(self.document.additional_resources):
			item = SubElement(manifest, "{http://www.idpf.org/2007/opf}item")
			item.set("href", resource_target)
			item.set("media-type", media_type)
			item.set("id", resource_target.replace('/', '-').replace('.','-'))
			item.tail = "\n    "

		# Add the (only) spine element
		spine = opf.findall(".//{http://www.idpf.org/2007/opf}spine")[0]
		item = SubElement(spine, "{http://www.idpf.org/2007/opf}itemref")
		item.set("idref", "main")

		# Manifest metadata
		title = opf.findall(".//{http://purl.org/dc/elements/1.1/}title")[0]
		title.text = self.document.title
		identifier = opf.findall(".//{http://purl.org/dc/elements/1.1/}identifier")[0]
		identifier.text = self.document.dated_uri
		date = opf.findall(".//{http://www.idpf.org/2007/opf}meta[@property='dcterms:modified']")[0]
		date.text = self.document.date.strftime(DATE_FORMAT_STRING)
		date = opf.findall(".//{http://www.idpf.org/2007/opf}meta[@property='dcterms:date']")[0]
		date.text = self.document.date.strftime(DATE_FORMAT_STRING)
		for editor in self.document.editors:
			creator = SubElement(metadata, "{http://purl.org/dc/elements/1.1/}creator")
			creator.set("role", "editor")
			creator.text = editor
			creator.tail = "\n    "
		for author in self.document.authors:
			creator = SubElement(metadata, "{http://purl.org/dc/elements/1.1/}creator")
			creator.set("role", "author")
			creator.text = author
			creator.tail = "\n    "

		# Push the manifest file into the book
		self.book.write_element('package.opf', opf)
开发者ID:iherman,项目名称:respec2epub,代码行数:67,代码来源:package.py

示例12: Element

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import tail [as 别名]
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import sys
from xml.etree.ElementTree import Element, SubElement, Comment, ElementTree

top = Element('top')

comment = Comment('Generato per PyMOTW')
top.append(comment)

child = SubElement(top, 'figlio')
child.text = 'Questo figlio contiene testo.'

child_with_tail = SubElement(top, 'figlio_con_coda')
child_with_tail.text = 'Questo figlio contiene testo normale.'
child_with_tail.tail = 'E testo "in coda".'

child_with_entity_ref = SubElement(top, 'figlio_con_rif_entita')
child_with_entity_ref.text = 'Questo & Quello'

ElementTree(top).write(sys.stdout)




开发者ID:robertopauletto,项目名称:PyMOTW-it_2.0,代码行数:24,代码来源:ElementTree_write.py

示例13: Element

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import tail [as 别名]
# There are three helper functions useful when creating a hierarchy of Element nodes
    # Element() creates a standard node
    # SubElement() attached a new node to a parent
    # Comment() creates a node that serializes using XML's comment syntax

top = Element('top')

comment = Comment("Generated for pystl")
top.append( comment )

child = SubElement( top, 'child' )
child.text = "This child contains text."

child_with_tail = SubElement( top, 'child_with_tail' )
child_with_tail.text = "This child has regular text."
child_with_tail.tail = "And 'tail' text."

child_with_entity_ref = SubElement( top, 'child_with_entity_ref' )
child_with_entity_ref.text = "This & That"

print "An XML string has been built:"
print ElementTree.tostring( top )
print

## 7.6.9 Pretty-Printing XML
# ElementTree doesn't add any whitespace, which is useful, but quite ugly
# xml.dom.minidom's toprettyxml() method makes it look a lot better for printing

def prettify(elem):
    """Return a pretty-printed XML string for the Element."""
    rough_string = ElementTree.tostring(elem, 'utf-8')
开发者ID:c4collins,项目名称:python-standard-library-examples,代码行数:33,代码来源:7.6-xml.etree.ElementTree.py

示例14: generate_opf

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import tail [as 别名]
def generate_opf(book_data):
	"""
    Generation of a new OPF object, combining the OPF information from the chapters.

    :param book_data: a data object collecting the necessary information for the creation of the new package file
    :return: Root of the generated package file; and :py:class:`ElementTree.Element` object
    """
	def add_manifest_item(the_manifest, bid, href, media_type, properties=None):
		"""
        Creation of a new manifest item. (Function to be used in a 'map')

        :param the_manifest: the whole manifest (parent of the item)
        :param bid: value of @id
        :param href: value of @href
        :param media_type: media type
        :param properties: list of possible values to be added to the `properties` attribute
        """
		item = SubElement(the_manifest, "{http://www.idpf.org/2007/opf}item")
		item.set("id", bid)
		item.set("href", href)
		item.set("media-type", media_type)
		if properties is not None:
			item.set("properties", properties)

	def add_metadata_item(the_opf, path, value, ns="http://purl.org/dc/elements/1.1/"):
		"""
        Add a metadata item.

        :param the_opf: metadata element (parent of the item)
        :param path: element to add the metadata item to; it may be extended with an attribute value in XPath syntax
        :param value: value to be set for the metadata
        :param ns: namespace of used in the path
        """
		item = the_opf.find((".//{%s}" % ns) + path)
		assert item is not None
		item.text = value

	# Parse the raw manifest file
	ET.register_namespace('', "http://www.idpf.org/2007/opf")
	opf = ElementTree(ET.fromstring(PACKAGE))
	# The manifest:
	manifest = opf.find(".//{http://www.idpf.org/2007/opf}manifest")
	metadata = opf.findall(".//{http://www.idpf.org/2007/opf}metadata")[0]

	# Manifest metadata
	add_metadata_item(opf, "title", book_data.title)
	add_metadata_item(opf, "identifier", book_data.id)
	add_metadata_item(opf, "meta[@property='dcterms:modified']", book_data.date.strftime(DATE_FORMAT_STRING), ns="http://www.idpf.org/2007/opf")
	add_metadata_item(opf, "meta[@property='dcterms:date']", book_data.date.strftime(DATE_FORMAT_STRING), ns="http://www.idpf.org/2007/opf")
	for editor in book_data.editors :
		creator = SubElement(metadata, "{http://purl.org/dc/elements/1.1/}creator")
		creator.set("role", "editor")
		creator.text = editor
		creator.tail = "\n    "
	for author in book_data.authors :
		creator = SubElement(metadata, "{http://purl.org/dc/elements/1.1/}creator")
		creator.set("role", "author")
		creator.text = author
		creator.tail = "\n    "

	# Add the static entries
	add_manifest_item(manifest, "nav", "nav.xhtml", "application/xhtml+xml", properties="nav")
	add_manifest_item(manifest, "start", "cover.xhtml", "application/xhtml+xml")
	add_manifest_item(manifest, "ncx", "toc.ncx", "application/x-dtbncx+xml")

	# Here is the real meat: collect all the chapter manifest items, and add them to the local manifest
	map(lambda x: manifest.append(x), reduce(lambda x, y: x + y, [c.opf.manifest for c in book_data.chapters], []))

	# A similar action should be done with the spine element
	spine = opf.find(".//{http://www.idpf.org/2007/opf}spine")
	map(lambda x: spine.append(x), reduce(lambda x, y: x + y, [c.opf.spine for c in book_data.chapters], []))

	return opf
开发者ID:iherman,项目名称:respec2epub-book,代码行数:75,代码来源:package.py

示例15: _create_opf

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import tail [as 别名]
	def _create_opf(self):
		"""
		Create the manifest file. Includes the list of resources, book metadata, and the spine. The manifest
		file is added to the book as ``package.opf``
		"""
		from .config import DEFAULT_FILES, CSS_LOGOS
		# Last step: the manifest file must be created
		# Parse the raw manifest file
		ET.register_namespace('', "http://www.idpf.org/2007/opf")
		opf = ElementTree(ET.fromstring(PACKAGE))

		# Add the 'main' file
		manifest = opf.findall(".//{http://www.idpf.org/2007/opf}manifest")[0]

		# Get the default resources first
		for (href, media_type, item_id, prop) in DEFAULT_FILES:
			item = SubElement(manifest, "{http://www.idpf.org/2007/opf}item")
			item.set("id", item_id)
			item.set("href", href)
			item.set("media-type", media_type)
			if prop != "":
				item.set("properties", prop)
			item.tail = "\n    "

		# Add the type-specific logo
		if self.document.doc_type in CSS_LOGOS:
			item = SubElement(manifest, "{http://www.idpf.org/2007/opf}item")
			item.set("id", "css-logo")
			item.set("href", CSS_LOGOS[self.document.doc_type][2])
			item.set("media-type", "image/png")
			item.tail = "\n    "

		item = SubElement(manifest, "{http://www.idpf.org/2007/opf}item")
		item.set("id", "main")
		item.set("href", "Overview.xhtml")
		item.set("media-type", "application/xhtml+xml")
		if self.document.properties is not None:
			item.set("properties", self.document.properties)
		item.tail = "\n    "

		# Add the additional resources
		for resource_target, media_type in self.document.additional_resources:
			item = SubElement(manifest, "{http://www.idpf.org/2007/opf}item")
			item.set("href", resource_target)
			item.set("media-type", media_type)
			item.set("id", resource_target.replace('/', '-'))
			item.tail = "\n    "

		# Add the (only) spine element
		spine = opf.findall(".//{http://www.idpf.org/2007/opf}spine")[0]
		item = SubElement(spine, "{http://www.idpf.org/2007/opf}itemref")
		item.set("idref", "main")

		# Remove the unnecessary item in spine (from the general template)
		to_remove = opf.findall(".//{http://www.idpf.org/2007/opf}itemref[@idref='toc']")[0]
		spine.remove(to_remove)

		# Manifest metadata
		title = opf.findall(".//{http://purl.org/dc/elements/1.1/}title")[0]
		title.text = self.document.title
		identifier = opf.findall(".//{http://purl.org/dc/elements/1.1/}identifier")[0]
		identifier.text = self.document.dated_uri
		date = opf.findall(".//{http://www.idpf.org/2007/opf}meta[@property='dcterms:modified']")[0]
		date.text = self.document.date.strftime("%Y-%m-%dT%M:%S:00Z")
		date = opf.findall(".//{http://www.idpf.org/2007/opf}meta[@property='dcterms:date']")[0]
		date.text = self.document.date.strftime("%Y-%m-%dT%M:%S:00Z")
		creator = opf.findall(".//{http://purl.org/dc/elements/1.1/}creator")[0]
		creator.text = self.document.editors

		# Push the manifest file into the book
		self.book.write_element('package.opf', opf)
开发者ID:gitter-badger,项目名称:respec2epub,代码行数:73,代码来源:package.py


注:本文中的xml.etree.ElementTree.SubElement.tail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。