示例#1
0
 def character_data_handler(self, data):
     childNodes = self.curNode.childNodes
     if childNodes and childNodes[-1].nodeType == TEXT_NODE:
         node = childNodes[-1]
         node.data = node.data + data
         return
     node = minidom.Text()
     node.data = node.data + data
     node.ownerDocument = self.document
     _append_child(self.curNode, node)
示例#2
0
 def character_data_handler(self, data):
     childNodes = self.curNode.childNodes
     if childNodes and childNodes[-1].nodeType == TEXT_NODE:
         node = childNodes[-1]
         node.data = node.data + data
         return
     node = minidom.Text()
     node.data = node.data + data
     node.ownerDocument = self.document
     _append_child(self.curNode, node)
示例#3
0
 def character_data_handler(self, data):
     childNodes = self.curNode.childNodes
     if childNodes and childNodes[-1].nodeType == TEXT_NODE:
         node = childNodes[-1]
         d = node.__dict__
         d['data'] = d['nodeValue'] = node.data + data
         return
     node = minidom.Text()
     d = node.__dict__
     d['data'] = d['nodeValue'] = node.data + data
     d['ownerDocument'] = self.document
     _append_child(self.curNode, node)
示例#4
0
    def start_element_handler(self, name, attributes):
        if ' ' in name:
            uri, localname, prefix, qname = _parse_ns_name(self, name)
        else:
            uri = EMPTY_NAMESPACE
            qname = name
            localname = None
            prefix = EMPTY_PREFIX
        node = minidom.Element(qname, uri, prefix, localname)
        node.ownerDocument = self.document
        _append_child(self.curNode, node)
        self.curNode = node

        if self._ns_ordered_prefixes:
            for prefix, uri in self._ns_ordered_prefixes:
                if prefix:
                    a = minidom.Attr(_intern(self, 'xmlns:' + prefix),
                                     XMLNS_NAMESPACE, prefix, "xmlns")
                else:
                    a = minidom.Attr("xmlns", XMLNS_NAMESPACE, "xmlns",
                                     EMPTY_PREFIX)
                # we're only interested in the URI as text at this point
                uri = uri or ""
                d = a.childNodes[0].__dict__
                d['data'] = d['nodeValue'] = uri
                d = a.__dict__
                d['value'] = d['nodeValue'] = uri
                d['ownerDocument'] = self.document
                _set_attribute_node(node, a)
            del self._ns_ordered_prefixes[:]

        if attributes:
            _attrs = node._attrs
            _attrsNS = node._attrsNS
            for i in range(0, len(attributes), 2):
                aname = attributes[i]
                value = attributes[i + 1]
                if ' ' in aname:
                    uri, localname, prefix, qname = _parse_ns_name(self, aname)
                    a = minidom.Attr(qname, uri, localname, prefix)
                    _attrs[qname] = a
                    _attrsNS[(uri, localname)] = a
                else:
                    a = minidom.Attr(aname, EMPTY_NAMESPACE, aname,
                                     EMPTY_PREFIX)
                    _attrs[aname] = a
                    _attrsNS[(EMPTY_NAMESPACE, aname)] = a
                d = a.childNodes[0].__dict__
                d['data'] = d['nodeValue'] = value
                d = a.__dict__
                d['ownerDocument'] = self.document
                d['value'] = d['nodeValue'] = value
                d['ownerElement'] = node
示例#5
0
    def start_element_handler(self, name, attributes):
        if ' ' in name:
            uri, localname, prefix, qname = _parse_ns_name(self, name)
        else:
            uri = EMPTY_NAMESPACE
            qname = name
            localname = None
            prefix = EMPTY_PREFIX
        node = minidom.Element(qname, uri, prefix, localname)
        node.ownerDocument = self.document
        _append_child(self.curNode, node)
        self.curNode = node

        if self._ns_ordered_prefixes:
            for prefix, uri in self._ns_ordered_prefixes:
                if prefix:
                    a = minidom.Attr(_intern(self, 'xmlns:' + prefix),
                                     XMLNS_NAMESPACE, prefix, "xmlns")
                else:
                    a = minidom.Attr("xmlns", XMLNS_NAMESPACE,
                                     "xmlns", EMPTY_PREFIX)
                # we're only interested in the URI as text at this point
                uri = uri or ""
                d = a.childNodes[0].__dict__
                d['data'] = d['nodeValue'] = uri
                d = a.__dict__
                d['value'] = d['nodeValue'] = uri
                d['ownerDocument'] = self.document
                _set_attribute_node(node, a)
            del self._ns_ordered_prefixes[:]

        if attributes:
            _attrs = node._attrs
            _attrsNS = node._attrsNS
            for i in range(0, len(attributes), 2):
                aname = attributes[i]
                value = attributes[i+1]
                if ' ' in aname:
                    uri, localname, prefix, qname = _parse_ns_name(self, aname)
                    a = minidom.Attr(qname, uri, localname, prefix)
                    _attrs[qname] = a
                    _attrsNS[(uri, localname)] = a
                else:
                    a = minidom.Attr(aname, EMPTY_NAMESPACE,
                                     aname, EMPTY_PREFIX)
                    _attrs[aname] = a
                    _attrsNS[(EMPTY_NAMESPACE, aname)] = a
                d = a.childNodes[0].__dict__
                d['data'] = d['nodeValue'] = value
                d = a.__dict__
                d['ownerDocument'] = self.document
                d['value'] = d['nodeValue'] = value
                d['ownerElement'] = node
示例#6
0
 def character_data_handler(self, data):
     childNodes = self.curNode.childNodes
     if childNodes and childNodes[-1].nodeType == TEXT_NODE:
         node = childNodes[-1]
         d = node.__dict__
         d['data'] = d['nodeValue'] = node.data + data
         return
     node = minidom.Text()
     d = node.__dict__
     d['data'] = d['nodeValue'] = node.data + data
     d['ownerDocument'] = self.document
     _append_child(self.curNode, node)
示例#7
0
 def start_element_handler(self, name, attributes):
     node = self.document.createElement(name)
     _append_child(self.curNode, node)
     self.curNode = node
     if attributes:
         for i in range(0, len(attributes), 2):
             a = minidom.Attr(attributes[i], EMPTY_NAMESPACE, None,
                              EMPTY_PREFIX)
             value = attributes[i + 1]
             a.value = value
             a.ownerDocument = self.document
             _set_attribute_node(node, a)
     if node is not self.document.documentElement:
         self._finish_start_element(node)
示例#8
0
    def start_element_handler(self, name, attributes):
        node = self.document.createElement(name)
        _append_child(self.curNode, node)
        self.curNode = node

        if attributes:
            for i in range(0, len(attributes), 2):
                a = minidom.Attr(attributes[i], EMPTY_NAMESPACE, None, EMPTY_PREFIX)
                value = attributes[i + 1]
                a.value = value
                a.ownerDocument = self.document
                _set_attribute_node(node, a)

        if node is not self.document.documentElement:
            self._finish_start_element(node)
    def start_element_handler(self, name, attributes):
        node = self.document.createElement(name)
        _append_child(self.curNode, node)
        self.curNode = node
        if attributes:
            for i in range(0, len(attributes), 2):
                a = minidom.Attr(attributes[i], EMPTY_NAMESPACE, None, EMPTY_PREFIX)
                value = attributes[i + 1]
                d = a.childNodes[0].__dict__
                d['data'] = d['nodeValue'] = value
                d = a.__dict__
                d['value'] = d['nodeValue'] = value
                d['ownerDocument'] = self.document
                _set_attribute_node(node, a)

        if node is not self.document.documentElement:
            self._finish_start_element(node)
示例#10
0
    def start_element_handler(self, name, attributes):
        if ' ' in name:
            uri, localname, prefix, qname = _parse_ns_name(self, name)
        else:
            uri = EMPTY_NAMESPACE
            qname = name
            localname = None
            prefix = EMPTY_PREFIX
        node = minidom.Element(qname, uri, prefix, localname)
        node.ownerDocument = self.document
        _append_child(self.curNode, node)
        self.curNode = node

        if self._ns_ordered_prefixes:
            for prefix, uri in self._ns_ordered_prefixes:
                if prefix:
                    a = minidom.Attr(_intern(self, 'xmlns:' + prefix),
                                     XMLNS_NAMESPACE, prefix, "xmlns")
                else:
                    a = minidom.Attr("xmlns", XMLNS_NAMESPACE, "xmlns",
                                     EMPTY_PREFIX)
                a.value = uri
                a.ownerDocument = self.document
                _set_attribute_node(node, a)
            del self._ns_ordered_prefixes[:]

        if attributes:
            node._ensure_attributes()
            _attrs = node._attrs
            _attrsNS = node._attrsNS
            for i in range(0, len(attributes), 2):
                aname = attributes[i]
                value = attributes[i + 1]
                if ' ' in aname:
                    uri, localname, prefix, qname = _parse_ns_name(self, aname)
                    a = minidom.Attr(qname, uri, localname, prefix)
                    _attrs[qname] = a
                    _attrsNS[(uri, localname)] = a
                else:
                    a = minidom.Attr(aname, EMPTY_NAMESPACE, aname,
                                     EMPTY_PREFIX)
                    _attrs[aname] = a
                    _attrsNS[(EMPTY_NAMESPACE, aname)] = a
                a.ownerDocument = self.document
                a.value = value
                a.ownerElement = node
示例#11
0
    def start_element_handler(self, name, attributes):
        if ' ' in name:
            uri, localname, prefix, qname = _parse_ns_name(self, name)
        else:
            uri = EMPTY_NAMESPACE
            qname = name
            localname = None
            prefix = EMPTY_PREFIX
        node = minidom.Element(qname, uri, prefix, localname)
        node.ownerDocument = self.document
        _append_child(self.curNode, node)
        self.curNode = node

        if self._ns_ordered_prefixes:
            for prefix, uri in self._ns_ordered_prefixes:
                if prefix:
                    a = minidom.Attr(_intern(self, 'xmlns:' + prefix),
                                     XMLNS_NAMESPACE, prefix, "xmlns")
                else:
                    a = minidom.Attr("xmlns", XMLNS_NAMESPACE,
                                     "xmlns", EMPTY_PREFIX)
                a.value = uri
                a.ownerDocument = self.document
                _set_attribute_node(node, a)
            del self._ns_ordered_prefixes[:]

        if attributes:
            node._ensure_attributes()
            _attrs = node._attrs
            _attrsNS = node._attrsNS
            for i in range(0, len(attributes), 2):
                aname = attributes[i]
                value = attributes[i+1]
                if ' ' in aname:
                    uri, localname, prefix, qname = _parse_ns_name(self, aname)
                    a = minidom.Attr(qname, uri, localname, prefix)
                    _attrs[qname] = a
                    _attrsNS[(uri, localname)] = a
                else:
                    a = minidom.Attr(aname, EMPTY_NAMESPACE,
                                     aname, EMPTY_PREFIX)
                    _attrs[aname] = a
                    _attrsNS[(EMPTY_NAMESPACE, aname)] = a
                a.ownerDocument = self.document
                a.value = value
                a.ownerElement = node
示例#12
0
 def start_doctype_decl_handler(self, doctypeName, systemId, publicId, has_internal_subset):
     doctype = self.document.implementation.createDocumentType(doctypeName, publicId, systemId)
     doctype.ownerDocument = self.document
     _append_child(self.document, doctype)
     self.document.doctype = doctype
     if self._filter and self._filter.acceptNode(doctype) == FILTER_REJECT:
         self.document.doctype = None
         del self.document.childNodes[-1]
         doctype = None
         self._parser.EntityDeclHandler = None
         self._parser.NotationDeclHandler = None
     if has_internal_subset:
         if doctype is not None:
             doctype.entities._seq = []
             doctype.notations._seq = []
         self._parser.CommentHandler = None
         self._parser.ProcessingInstructionHandler = None
         self._parser.EndDoctypeDeclHandler = self.end_doctype_decl_handler
示例#13
0
    def start_element_handler(self, name, attributes):
        node = self.document.createElement(name)
        _append_child(self.curNode, node)
        self.curNode = node
        if attributes:
            for i in range(0, len(attributes), 2):
                a = minidom.Attr(attributes[i], EMPTY_NAMESPACE, None, EMPTY_PREFIX)
                value = attributes[i + 1]
                d = a.childNodes[0].__dict__
                d['data'] = d['nodeValue'] = value
                d = a.__dict__
                d['value'] = d['nodeValue'] = value
                d['ownerDocument'] = self.document
                _set_attribute_node(node, a)

        if node is not self.document.documentElement:
            self._finish_start_element(node)
        return
示例#14
0
 def character_data_handler_cdata(self, data):
     childNodes = self.curNode.childNodes
     if self._cdata:
         if self._cdata_continue and childNodes[-1].nodeType == CDATA_SECTION_NODE:
             childNodes[-1].appendData(data)
             return
         node = self.document.createCDATASection(data)
         self._cdata_continue = True
     elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
         node = childNodes[-1]
         value = node.data + data
         node.data = value
         return
     else:
         node = minidom.Text()
         node.data = data
         node.ownerDocument = self.document
     _append_child(self.curNode, node)
示例#15
0
 def character_data_handler_cdata(self, data):
     childNodes = self.curNode.childNodes
     if self._cdata:
         if (self._cdata_continue
                 and childNodes[-1].nodeType == CDATA_SECTION_NODE):
             childNodes[-1].appendData(data)
             return
         node = self.document.createCDATASection(data)
         self._cdata_continue = True
     elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
         node = childNodes[-1]
         value = node.data + data
         node.data = value
         return
     else:
         node = minidom.Text()
         node.data = data
         node.ownerDocument = self.document
     _append_child(self.curNode, node)
示例#16
0
 def start_doctype_decl_handler(self, doctypeName, systemId, publicId, has_internal_subset):
     doctype = self.document.implementation.createDocumentType(doctypeName, publicId, systemId)
     doctype.ownerDocument = self.document
     _append_child(self.document, doctype)
     self.document.doctype = doctype
     if self._filter and self._filter.acceptNode(doctype) == FILTER_REJECT:
         self.document.doctype = None
         del self.document.childNodes[-1]
         doctype = None
         self._parser.EntityDeclHandler = None
         self._parser.NotationDeclHandler = None
     if has_internal_subset:
         if doctype is not None:
             doctype.entities._seq = []
             doctype.notations._seq = []
         self._parser.CommentHandler = None
         self._parser.ProcessingInstructionHandler = None
         self._parser.EndDoctypeDeclHandler = self.end_doctype_decl_handler
     return
示例#17
0
 def comment_handler(self, data):
     node = self.document.createComment(data)
     _append_child(self.curNode, node)
     if self._filter and self._filter.acceptNode(node) == FILTER_REJECT:
         self.curNode.removeChild(node)
示例#18
0
 def pi_handler(self, target, data):
     node = self.document.createProcessingInstruction(target, data)
     _append_child(self.curNode, node)
     if self._filter and self._filter.acceptNode(node) == FILTER_REJECT:
         self.curNode.removeChild(node)
示例#19
0
 def comment_handler(self, data):
     node = self.document.createComment(data)
     _append_child(self.curNode, node)
     if self._filter and self._filter.acceptNode(node) == FILTER_REJECT:
         self.curNode.removeChild(node)
示例#20
0
 def pi_handler(self, target, data):
     node = self.document.createProcessingInstruction(target, data)
     _append_child(self.curNode, node)
     if self._filter and self._filter.acceptNode(node) == FILTER_REJECT:
         self.curNode.removeChild(node)