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


Python dom.minidom方法代码示例

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


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

示例1: setValue

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import minidom [as 别名]
def setValue( self, val ):
		"""Sets the text value for this instance.  If it doesn't already 
		have a child who is of :class:`xml.dom.minidom.Text` type, then 
		it will add one and set the data of it to the inputed value.  The 
		inputed value will automatically be converted to a string value to 
		avoid errors as well.

		"""
		if ( self._object ):
			# find existing text node & update
			for child in self._object.childNodes:
				if ( isinstance( child, xml.dom.minidom.Text ) ):
					child.data = unicode( val )
					return True
			
			# create new text node
			text = self._document().createTextNode( unicode( val ) )
			self._object.appendChild( text )
			return True
		return False 
开发者ID:blurstudio,项目名称:cross3d,代码行数:22,代码来源:xmlelement.py

示例2: extract_target_from_xml

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import minidom [as 别名]
def extract_target_from_xml(filename):
    if not os.path.exists(filename):
        raise IOError(filename + " not exists !")
    # 使用minidom解析器打开 XML 文档
    DOMTree = xml.dom.minidom.parse(filename)
    collection = DOMTree.documentElement
    # 获取集合中所有的目标
    targets = collection.getElementsByTagName("object")
    res = []
    for target in targets:
        target_name = target.getElementsByTagName('name')[0].childNodes[0].data
        bndbox = target.getElementsByTagName("bndbox")[0]
        xmin = bndbox.getElementsByTagName("xmin")[0].childNodes[0].data
        ymin = bndbox.getElementsByTagName("ymin")[0].childNodes[0].data
        xmax = bndbox.getElementsByTagName("xmax")[0].childNodes[0].data
        ymax = bndbox.getElementsByTagName("ymax")[0].childNodes[0].data
        res.append([int(xmin), int(ymin), int(xmax), int(ymax), target_name])
    return res

# 原始数据中多目标的显示 
开发者ID:liuguiyangnwpu,项目名称:DL.EyeSight,代码行数:22,代码来源:tools.py

示例3: removeComments

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import minidom [as 别名]
def removeComments(element):
    """
       Removes comments from the element and its children.
    """
    global _num_bytes_saved_in_comments
    num = 0

    if isinstance(element, xml.dom.minidom.Comment):
        _num_bytes_saved_in_comments += len(element.data)
        element.parentNode.removeChild(element)
        num += 1
    else:
        for subelement in element.childNodes[:]:
            num += removeComments(subelement)

    return num 
开发者ID:hchauvet,项目名称:beampy,代码行数:18,代码来源:scour.py

示例4: testNormalizedAfterLoad

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import minidom [as 别名]
def testNormalizedAfterLoad(self):
        """
        Introduced this test on jython because 
        1. Cpython guarantees, by the use of xml.dom.expatbuilder, 
           that all text nodes are normalized after loading.
        2. Jython has no expat, and thus uses xml.dom.pulldom.parse 
           (which uses any java SAX2 compliant parser), and which makes 
           no guarantees about text node normalization.
        Thus we have to check if text nodes are normalized after a parse.
        See this bug for further information
        minidom chunks the character input on multi-line values
        http://bugs.jython.org/issue1614
        """
        num_lines = 2
        # Up to 16K lines should be enough to guarantee failure without normalization
        while num_lines <= 2**14:
            doc_content = "\n".join( ("Line %d" % i for i in xrange(num_lines)) )
            doc_text = "<document>%s</document>" % doc_content
            dom = parseString(doc_text)
            node_content = dom.getElementsByTagName("document")[0].childNodes[0].nodeValue
            self.confirm(node_content == doc_content, "testNormalizedAfterLoad")
            num_lines *= 2 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:24,代码来源:test_minidom.py

示例5: create_nonempty_doctype

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import minidom [as 别名]
def create_nonempty_doctype():
    doctype = getDOMImplementation().createDocumentType("doc", None, None)
    doctype.entities._seq = []
    doctype.notations._seq = []
    notation = xml.dom.minidom.Notation("my-notation", None,
                                        "http://xml.python.org/notations/my")
    doctype.notations._seq.append(notation)
    entity = xml.dom.minidom.Entity("my-entity", None,
                                    "http://xml.python.org/entities/my",
                                    "my-notation")
    entity.version = "1.0"
    entity.encoding = "utf-8"
    entity.actualEncoding = "us-ascii"
    doctype.entities._seq.append(entity)
    return doctype 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_minidom.py

示例6: testGetElementsByTagNameNS

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import minidom [as 别名]
def testGetElementsByTagNameNS(self):
        d="""<foo xmlns:minidom='http://pyxml.sf.net/minidom'>
        <minidom:myelem/>
        </foo>"""
        dom = parseString(d)
        elems = dom.getElementsByTagNameNS("http://pyxml.sf.net/minidom",
                                           "myelem")
        self.confirm(len(elems) == 1
                and elems[0].namespaceURI == "http://pyxml.sf.net/minidom"
                and elems[0].localName == "myelem"
                and elems[0].prefix == "minidom"
                and elems[0].tagName == "minidom:myelem"
                and elems[0].nodeName == "minidom:myelem")
        dom.unlink() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_minidom.py

示例7: testRenameOther

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import minidom [as 别名]
def testRenameOther(self):
        # We have to create a comment node explicitly since not all DOM
        # builders used with minidom add comments to the DOM.
        doc = xml.dom.minidom.getDOMImplementation().createDocument(
            xml.dom.EMPTY_NAMESPACE, "e", None)
        node = doc.createComment("comment")
        self.assertRaises(xml.dom.NotSupportedErr, doc.renameNode, node,
                          xml.dom.EMPTY_NAMESPACE, "foo")
        doc.unlink() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_minidom.py

示例8: __eq__

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import minidom [as 别名]
def __eq__( self, other ):
		""" checks to see if the wrapper <xml.dom.minidom.Element> instance is the same """
		result = False
		if ( isinstance( other, XMLElement ) ):
			result = ( self._object == other._object )
		return result 
开发者ID:blurstudio,项目名称:cross3d,代码行数:8,代码来源:xmlelement.py

示例9: __getattr__

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import minidom [as 别名]
def __getattr__( self, key ):
		""" pass along all unknown attributes to the <xml.dom.minidom.Element> class instance """
		return getattr( self._object, key ) 
开发者ID:blurstudio,项目名称:cross3d,代码行数:5,代码来源:xmlelement.py

示例10: __init__

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import minidom [as 别名]
def __init__( self, object, filename = '' ):
		""" initialize the class with an <xml.dom.minidom.Element> instance """
		if ( object == None ):
			object = xml.dom.minidom.Element(None)
		self._object = object
		self.__file__ = filename
		# Used to allow saving empty attributes.
		self.allowEmptyAttrs = False 
开发者ID:blurstudio,项目名称:cross3d,代码行数:10,代码来源:xmlelement.py

示例11: _document

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import minidom [as 别名]
def _document( self ):
		""" recursese up the hierarchy to find the parent who is a <xml.dom.minidom.Document> class """
		out = self._object
		while ( out and not isinstance( out, xml.dom.minidom.Document ) ):
			out = out.parentNode
		return out 
开发者ID:blurstudio,项目名称:cross3d,代码行数:8,代码来源:xmlelement.py

示例12: _children

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import minidom [as 别名]
def _children( self ):
		""" collects the minidom child nodes which are <xml.dom.minidom.Element> types """
		if ( self._object ):
			return [ child for child in self._object.childNodes if isinstance( child, xml.dom.minidom.Element ) ]
		return [] 
开发者ID:blurstudio,项目名称:cross3d,代码行数:7,代码来源:xmlelement.py

示例13: children

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import minidom [as 别名]
def children( self ):
		"""Collects all the child nodes of this element whose child type is an
		:class:`xml.dom.minidom.Element`, wrapping each child as an 
		:class:`XMLElement`.

		"""
		if ( self._object ):
			return [ XMLElement( child, self.__file__ ) for child in self._object.childNodes if isinstance( child, xml.dom.minidom.Element ) ]
		return [] 
开发者ID:blurstudio,项目名称:cross3d,代码行数:11,代码来源:xmlelement.py

示例14: index

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import minidom [as 别名]
def index( self, object ):
		"""Finds the index of the inputed child object in this instance's 
		XMLElement children, returning -1 if it cannot be found.

		"""
		if ( self._object ):
			if ( isinstance( object, XMLElement ) ):
				if ( object._object in self._object.childNodes ):
					return self._object.childNodes.index( object._object )
			elif ( isinstance( object, xml.dom.minidom.Element ) ):
				if ( object in self._object.childNodes ):
					return self._object.childNodes.index( object )
		return -1 
开发者ID:blurstudio,项目名称:cross3d,代码行数:15,代码来源:xmlelement.py

示例15: parent

# 需要导入模块: from xml import dom [as 别名]
# 或者: from xml.dom import minidom [as 别名]
def parent(self):
		if (self.parentNode and isinstance(self.parentNode, xml.dom.minidom.Element)):
			return XMLElement(self.parentNode, self.__file__)
		return None 
开发者ID:blurstudio,项目名称:cross3d,代码行数:6,代码来源:xmlelement.py


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