def attrs( self, document:'Document', node:Node, attributes:Optional[Union[Dict[str,str],Iterable[str]]]=None ): attrs = attributes.items() if isinstance(attributes, dict) or isinstance(attributes, OrderedDict) else enumerate(attributes) for name, value in attrs: if self.isAttributeValue(value): node.setAttribute(name, str(value)) else: node.appendChild(self.node( document, name, value )) return node
def add( self, document, node:Node, child:Node ) -> Node: if node.nodeType == Node.TEXT_NODE: return node elif isinstance(child, dict) or isinstance(child, OrderedDict): for k,v in child.items(): if self.isAttributeValue(v): node.setAttributeNS(None, k, str(v)) else: node.appendChild(self.node( document, k, v )) elif isinstance(child, str) or isinstance(child, str): node.appendChild(document.createTextNode(child)) elif isinstance(child, list) or isinstance(child, tuple): for i,v in enumerate(child): node.appendChild(self.node( document, "item", {"index":i}, v)) elif child: node.appendChild(child) return node