def createElementNS(self, namespaceURI, qualifiedName): from Element import Element if not get_name_pattern().match(qualifiedName): raise InvalidCharacterErr() (prefix, localName) = SplitQName(qualifiedName) if prefix == 'xml' and namespaceURI != XML_NAMESPACE: raise NamespaceErr() if prefix and not namespaceURI: raise NamespaceErr() elif namespaceURI == '': raise NamespaceErr("Use None instead of '' for empty namespace") return Element(self, qualifiedName, namespaceURI, prefix, localName)
def createAttributeNS(self, namespaceURI, qualifiedName): if not get_name_pattern().match(qualifiedName): raise InvalidCharacterErr() from Attr import Attr (prefix, localName) = SplitQName(qualifiedName) if prefix == 'xml' and namespaceURI != XML_NAMESPACE: raise NamespaceErr() if localName == 'xmlns': if namespaceURI != XMLNS_NAMESPACE: raise NamespaceErr() return Attr(self, qualifiedName, XMLNS_NAMESPACE, 'xmlns', prefix) elif namespaceURI == '': raise NamespaceErr("Use None instead of '' for empty namespace") else: if (not namespaceURI and prefix) or (not prefix and namespaceURI): raise NamespaceErr() return Attr(self, qualifiedName, namespaceURI, prefix, localName)
def removeNamedItemNS(self, namespaceURI, localName): if namespaceURI == '': raise NamespaceErr("Use None instead of '' for empty namespace") name = (namespaceURI, localName) old = self.get(name) if not old: raise NotFoundErr() del self[name] self._positions.remove(name) return old
def getElementsByTagNameNS(self, namespaceURI, localName): if namespaceURI == '': raise NamespaceErr("Use None instead of '' for empty namespace") nodeList = implementation._4dom_createNodeList([]) root = self.documentElement if root: if ((namespaceURI == '*' or namespaceURI == root.namespaceURI) and (localName == '*' or localName == root.localName)): nodeList.append(root) nodeList.extend( list(root.getElementsByTagNameNS(namespaceURI, localName))) return nodeList
def setNamedItemNS(self, arg): if self._ownerDocument != arg.ownerDocument: raise WrongDocumentErr() if arg.nodeType == Node.ATTRIBUTE_NODE and arg.ownerElement != None: raise InuseAttributeErr() if arg.namespaceURI == '': raise NamespaceErr("Use None instead of '' for empty namespace") name = (arg.namespaceURI, arg.localName) retval = self.get(name) UserDict.UserDict.__setitem__(self, name, arg) if not retval: self._positions.append(name) return retval
def _set_prefix(self, value): # Check for invalid characters if not get_name_pattern().match(value): raise InvalidCharacterErr() if (self.__dict__['__namespaceURI'] is None or ':' in value or (value == 'xml' and self.__dict__['__namespaceURI'] != XML_NAMESPACE)): raise NamespaceErr() self.__dict__['__prefix'] = value self.__dict__['__nodeName'] = '%s:%s' % ( value, self.__dict__['__localName'])
def getElementsByTagNameNS(self, namespaceURI, localName): if namespaceURI == '': raise NamespaceErr("Use None instead of '' for empty namespace") nodeList = implementation._4dom_createNodeList() elements = filter( lambda node, type=Node.ELEMENT_NODE: node.nodeType == type, self.childNodes) for element in elements: if ((namespaceURI == '*' or element.namespaceURI == namespaceURI) and (localName == '*' or element.localName == localName)): nodeList.append(element) nodeList.extend( list(element.getElementsByTagNameNS(namespaceURI, localName))) return nodeList
def getNamedItemNS(self, namespaceURI, localName): if namespaceURI == '': raise NamespaceErr("Use None instead of '' for empty namespace") return self.get((namespaceURI, localName))