當前位置: 首頁>>代碼示例>>Python>>正文


Python Node.DOCUMENT_NODE屬性代碼示例

本文整理匯總了Python中xml.dom.Node.DOCUMENT_NODE屬性的典型用法代碼示例。如果您正苦於以下問題:Python Node.DOCUMENT_NODE屬性的具體用法?Python Node.DOCUMENT_NODE怎麽用?Python Node.DOCUMENT_NODE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在xml.dom.Node的用法示例。


在下文中一共展示了Node.DOCUMENT_NODE屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: getNodeDetails

# 需要導入模塊: from xml.dom import Node [as 別名]
# 或者: from xml.dom.Node import DOCUMENT_NODE [as 別名]
def getNodeDetails(self, node):
        if node.nodeType == Node.DOCUMENT_TYPE_NODE:
            return _base.DOCTYPE, node.name, node.publicId, node.systemId

        elif node.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE):
            return _base.TEXT, node.nodeValue

        elif node.nodeType == Node.ELEMENT_NODE:
            attrs = {}
            for attr in node.attributes.keys():
                attr = node.getAttributeNode(attr)
                attrs[(attr.namespaceURI,attr.localName)] = attr.value
            return (_base.ELEMENT, node.namespaceURI, node.nodeName, 
                    attrs, node.hasChildNodes())

        elif node.nodeType == Node.COMMENT_NODE:
            return _base.COMMENT, node.nodeValue

        elif node.nodeType in (Node.DOCUMENT_NODE, Node.DOCUMENT_FRAGMENT_NODE):
            return (_base.DOCUMENT,)

        else:
            return _base.UNKNOWN, node.nodeType 
開發者ID:caronc,項目名稱:nzb-subliminal,代碼行數:25,代碼來源:dom.py

示例2: __init__

# 需要導入模塊: from xml.dom import Node [as 別名]
# 或者: from xml.dom.Node import DOCUMENT_NODE [as 別名]
def __init__(self, context, options=None):
        if context.nodeType == DOCUMENT_NODE:
            self.originalDocument = context
            self.context = context
        else:
            self.originalDocument = context.ownerDocument
            self.context = context
        ExpatBuilder.__init__(self, options) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:10,代碼來源:expatbuilder.py

示例3: getNodeDetails

# 需要導入模塊: from xml.dom import Node [as 別名]
# 或者: from xml.dom.Node import DOCUMENT_NODE [as 別名]
def getNodeDetails(self, node):
        if node.nodeType == Node.DOCUMENT_TYPE_NODE:
            return base.DOCTYPE, node.name, node.publicId, node.systemId

        elif node.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE):
            return base.TEXT, node.nodeValue

        elif node.nodeType == Node.ELEMENT_NODE:
            attrs = {}
            for attr in list(node.attributes.keys()):
                attr = node.getAttributeNode(attr)
                if attr.namespaceURI:
                    attrs[(attr.namespaceURI, attr.localName)] = attr.value
                else:
                    attrs[(None, attr.name)] = attr.value
            return (base.ELEMENT, node.namespaceURI, node.nodeName,
                    attrs, node.hasChildNodes())

        elif node.nodeType == Node.COMMENT_NODE:
            return base.COMMENT, node.nodeValue

        elif node.nodeType in (Node.DOCUMENT_NODE, Node.DOCUMENT_FRAGMENT_NODE):
            return (base.DOCUMENT,)

        else:
            return base.UNKNOWN, node.nodeType 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:28,代碼來源:dom.py

示例4: getNodeDetails

# 需要導入模塊: from xml.dom import Node [as 別名]
# 或者: from xml.dom.Node import DOCUMENT_NODE [as 別名]
def getNodeDetails(self, node):
        if node.nodeType == Node.DOCUMENT_TYPE_NODE:
            return _base.DOCTYPE, node.name, node.publicId, node.systemId

        elif node.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE):
            return _base.TEXT, node.nodeValue

        elif node.nodeType == Node.ELEMENT_NODE:
            attrs = {}
            for attr in list(node.attributes.keys()):
                attr = node.getAttributeNode(attr)
                if attr.namespaceURI:
                    attrs[(attr.namespaceURI, attr.localName)] = attr.value
                else:
                    attrs[(None, attr.name)] = attr.value
            return (_base.ELEMENT, node.namespaceURI, node.nodeName,
                    attrs, node.hasChildNodes())

        elif node.nodeType == Node.COMMENT_NODE:
            return _base.COMMENT, node.nodeValue

        elif node.nodeType in (Node.DOCUMENT_NODE, Node.DOCUMENT_FRAGMENT_NODE):
            return (_base.DOCUMENT,)

        else:
            return _base.UNKNOWN, node.nodeType 
開發者ID:jpush,項目名稱:jbox,代碼行數:28,代碼來源:dom.py

示例5: _toprettyxml_node

# 需要導入模塊: from xml.dom import Node [as 別名]
# 或者: from xml.dom.Node import DOCUMENT_NODE [as 別名]
def _toprettyxml_node(self, indent="\t", newl="\n", encoding = None):
        _collapse(self)
        # indent = the indentation string to prepend, per level
        # newl = the newline string to append
        writer = minidom._get_StringIO()
        if encoding is not None:
                import codecs
                # Can't use codecs.getwriter to preserve 2.0 compatibility
                writer = codecs.lookup(encoding)[3](writer)
        if self.nodeType == Node.DOCUMENT_NODE:
                # Can pass encoding only to document, to put it into XML header
                self.writexml(writer, "", indent, newl, encoding)
        else:
                self.writexml(writer, "", indent, newl)
        return writer.getvalue() 
開發者ID:krintoxi,項目名稱:NoobSec-Toolkit,代碼行數:17,代碼來源:prettyprint.py


注:本文中的xml.dom.Node.DOCUMENT_NODE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。