def setAttribute(self, name, value): if not IsDOMString(value): raise SyntaxErr() if not get_name_pattern().match(name): raise InvalidCharacterErr() attr = self.attributes.getNamedItem(name) if attr: attr.value = value else: attr = self.ownerDocument.createAttribute(name) attr.value = value self.setAttributeNode(attr)
def createProcessingInstruction(self, target, data): if not get_name_pattern().match(target): raise InvalidCharacterErr() #FIXME: Unicode support # Technically, chacters from the unicode surrogate blocks are illegal. #for c in target: # if c in unicode_surrogate_blocks: # raise InvalidCharacterErr() from ProcessingInstruction import ProcessingInstruction return ProcessingInstruction(self, target, data)
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 createProcessingInstruction(self, target, data): if not get_name_pattern().match(target): raise InvalidCharacterErr() #FIXME: Unicode support # Technically, chacters from the unicode surrogate blocks are illegal. #for c in target: # if c in unicode_surrogate_blocks: # raise InvalidCharacterErr() from ProcessingInstruction import ProcessingInstruction return ProcessingInstruction(self, target, data);
def setAttributeNS(self, namespaceURI, qualifiedName, value): if not IsDOMString(value): raise SyntaxErr() if not get_name_pattern().match(qualifiedName): raise InvalidCharacterErr() prefix, localName = SplitQName(qualifiedName) attr = self.attributes.getNamedItemNS(namespaceURI, localName) if attr: attr.value = value else: attr = self.ownerDocument.createAttributeNS(namespaceURI, qualifiedName) attr.value = value self.setAttributeNodeNS(attr) return
def setAttributeNS(self, namespaceURI, qualifiedName, value): if not IsDOMString(value): raise SyntaxErr() if not get_name_pattern().match(qualifiedName): raise InvalidCharacterErr() prefix, localName = SplitQName(qualifiedName) attr = self.attributes.getNamedItemNS(namespaceURI, localName) if attr: attr.value = value else: attr = self.ownerDocument.createAttributeNS( namespaceURI, qualifiedName) attr.value = value self.setAttributeNodeNS(attr) return
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 createEntityReference(self, name): if not get_name_pattern().match(name): raise InvalidCharacterErr() from EntityReference import EntityReference return EntityReference(self, name)
def createElement(self, tagname): if not get_name_pattern().match(tagname): raise InvalidCharacterErr() from Element import Element return Element(self, tagname, EMPTY_NAMESPACE, None, None)
def createAttribute(self, name): if not get_name_pattern().match(name): raise InvalidCharacterErr() import Attr return Attr.Attr(self, name, EMPTY_NAMESPACE, None, None)