Beispiel #1
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
Beispiel #2
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
Beispiel #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)
Beispiel #4
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)
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
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
         d = node.__dict__
         d['data'] = d['nodeValue'] = value
         return
     else:
         node = minidom.Text()
         d = node.__dict__
         d['data'] = d['nodeValue'] = data
         d['ownerDocument'] = self.document
     _append_child(self.curNode, node)
Beispiel #8
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
         d = node.__dict__
         d['data'] = d['nodeValue'] = value
         return
     else:
         node = minidom.Text()
         d = node.__dict__
         d['data'] = d['nodeValue'] = data
         d['ownerDocument'] = self.document
     _append_child(self.curNode, node)
Beispiel #9
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)
Beispiel #10
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)
Beispiel #11
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)
Beispiel #12
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)