def XmlElement(tagName, text=None, **attrs): elem = Document().createElement(tagName) if text: textNode = Document().createTextNode(escape(text)) elem.appendChild(textNode) if attrs: for attr, value in attrs.iteritems(): elem.setAttribute(attr, escape(str(value))) return elem
def xml(self): """ It returns xml.dom.minidom.Element representation of this SubGraph. """ subXML = Document().createElement("SubGraph") subXML.setAttribute("id", "{0}".format(self.id)) for mod in self.modules.values(): subXML.appendChild(mod.xml()) for con in self._connections: subXML.appendChild(con.xml()) return subXML
def xml(self): """ It returns xml.dom.minidom.Element representation of this Connection. """ conXML = Document().createElement("Connection") conXML.setAttribute("id", "{0}".format(self.id)) conXML.setAttribute("source_port_id", "{0}".format(self.source.id)) conXML.setAttribute("destination_port_id", "{0}".format(self.destination.id)) conXML.setAttribute("source_module_id", "{0}".format(self.sModule.id)) conXML.setAttribute("destination_module_id", "{0}".format(self.dModule.id)) return conXML
def xml(self): """ It returns xml.dom.minidom.Element representation of this Graph. """ graphXML = Document().createElement("Graph") graphXML.setAttribute("name", "{0}".format(self.name)) graphXML.setAttribute("tags", "{0}".format(self.tags)) graphXML.appendChild( Document().createTextNode("{0}".format(self.description)) ) for sub in self.subgraphs.values(): graphXML.appendChild(sub.xml()) return graphXML
def xml(self): """ It returns xml.dom.minidom.Element representation of this Graph. """ graphXML = Document().createElement("Graph") graphXML.setAttribute("name", "{0}".format(self.name)) graphXML.setAttribute("tags", "{0}".format(self.tags)) graphXML.appendChild(Document().createTextNode("{0}".format( self.description))) for sub in self.subgraphs.values(): graphXML.appendChild(sub.xml()) return graphXML
def domainElement(domainType): """ Creates a <domain> element in a L{libvirt document<libvirtDocument>} when passed the hypervisor type. @param domainType: hypervisor type @type domainType: String @return: <domain> Element @rtype: DOM Element """ domain = Document().createElement('domain') domain.setAttribute('type', domainType) return domain
def save_xml(self, xmlparent=None): typ = self.nodetype() if xmlparent is None: assert typ == Document.DOCUMENT_NODE xmlnode = Document() xmlnode.ownerDocument = xmlnode else: if typ == Document.ATTRIBUTE_NODE: xmlnode = xmlparent.ownerDocument.createAttribute(self.name()) elif typ == Document.CDATA_SECTION_NODE: xmlnode = xmlparent.ownerDocument.createCDATASection() elif typ == Document.COMMENT_NODE: xmlnode = xmlparent.ownerDocument.createComment( self.attribute("data")) elif typ == Document.DOCUMENT_FRAGMENT_NODE: xmlnode = xmlparent.ownerDocument.createDocumentFragment() elif typ == Document.DOCUMENT_NODE: raise UserWarning("cannot create a DOCUMENT_NODE from there") elif typ == Document.DOCUMENT_TYPE_NODE: raise UserWarning( "cannot create a DOCUMENT_TYPE_NODE from there") elif typ == Document.ELEMENT_NODE: xmlnode = xmlparent.ownerDocument.createElement( self.nodename()) for key in self.attributes(): xmlnode.setAttribute(key, self.attribute(key)) elif typ == Document.ENTITY_NODE: raise UserWarning("cannot create a ENTITY_NODE from there") elif typ == Document.ENTITY_REFERENCE_NODE: raise UserWarning( "cannot create a ENTITY_REFERENCE_NODE from there") elif typ == Document.NOTATION_NODE: raise UserWarning("cannot create a NOTATION_NODE from there") elif typ == Document.PROCESSING_INSTRUCTION_NODE: xmlnode = xmlparent.ownerDocument.createProcessingInstruction() elif typ == Document.TEXT_NODE: xmlnode = xmlparent.ownerDocument.createTextNode( self.attribute("data")) else: raise UserWarning("problem") #xml tree save xmlparent.appendChild(xmlnode) for child in self.children(): child.save_xml(xmlnode) return xmlnode
def createLinkElement(self): a = Document().createElement("a") text = '' http = self.link_content[0] if len(self.link_content) == 1: text = Document().createTextNode(http) a.appendChild(text) else: in_count = 1 if(self.link_content[1]=='|'): in_count = 2 self.new_parser.tokenList = self.link_content[in_count:] self.new_parser.count = 0 container = self.new_parser.parseToken("*container",'') nodes = container.childNodes for smallnode in nodes[:]: a.appendChild(smallnode) a.setAttribute("href", http) return a
def __findInheritanceRecursive(self, parentName): """Returns minidom structure - whole structure of ancestors of class specified by parentName""" rootLst = [] # ask if anybody inherit from parentName, if so, create subentry for child in filter(lambda x: len(x.inheritance) > 0, self.classInstances): if parentName in child.inheritance: subEntry = Document().createElement("class") subEntry.setAttribute("name", child.name) subEntry.setAttribute("kind", child.kind) children = self.__findInheritanceRecursive(child.name) if len(children) != 0: for ch in children: subEntry.appendChild(ch) # else: # subEntry.appendChild(Document().createTextNode("")) # insert empty node, to prevent having self closing node rootLst.append(subEntry) return rootLst
def toElement(self): """ Create and return a DOM element for this object @return: DOM element based on the infomation stored within the object. @rtype: DOM element. """ childF = Document().createElement('File') if self.file_id != None: childF.setAttribute("ovf:id", self.file_id) if self.size != None: childF.setAttribute("ovf:size", self.size) if self.href != None: childF.setAttribute("ovf:href", self.href) if self.compression != None: childF.setAttribute("ovf:compression", self.compression) if self.chunksize != None: childF.setAttribute("ovf:chunkSize", self.chunksize) return(childF)
def save_xml(self, xmlparent=None): typ = self.nodetype() if xmlparent is None: assert typ == Document.DOCUMENT_NODE xmlnode = Document() xmlnode.ownerDocument = xmlnode else: if typ == Document.ATTRIBUTE_NODE: xmlnode = xmlparent.ownerDocument.createAttribute(self.name()) elif typ == Document.CDATA_SECTION_NODE: xmlnode = xmlparent.ownerDocument.createCDATASection() elif typ == Document.COMMENT_NODE: xmlnode = xmlparent.ownerDocument.createComment(self.attribute("data")) elif typ == Document.DOCUMENT_FRAGMENT_NODE: xmlnode = xmlparent.ownerDocument.createDocumentFragment() elif typ == Document.DOCUMENT_NODE: raise UserWarning("cannot create a DOCUMENT_NODE from there") elif typ == Document.DOCUMENT_TYPE_NODE: raise UserWarning("cannot create a DOCUMENT_TYPE_NODE from there") elif typ == Document.ELEMENT_NODE: xmlnode = xmlparent.ownerDocument.createElement(self.nodename()) for key in self.attributes(): xmlnode.setAttribute(key, self.attribute(key)) elif typ == Document.ENTITY_NODE: raise UserWarning("cannot create a ENTITY_NODE from there") elif typ == Document.ENTITY_REFERENCE_NODE: raise UserWarning("cannot create a ENTITY_REFERENCE_NODE from there") elif typ == Document.NOTATION_NODE: raise UserWarning("cannot create a NOTATION_NODE from there") elif typ == Document.PROCESSING_INSTRUCTION_NODE: xmlnode = xmlparent.ownerDocument.createProcessingInstruction() elif typ == Document.TEXT_NODE: xmlnode = xmlparent.ownerDocument.createTextNode(self.attribute("data")) else: raise UserWarning("problem") # xml tree save xmlparent.appendChild(xmlnode) for child in self.children(): child.save_xml(xmlnode) return xmlnode
def getConnectionsXML( self, address=None, port=None, protocol=None, kind=None): r = [ ] for t in self.getConnections(address, port, protocol, kind): m = Document().createElement('connection') m.setAttribute('addr', t[0]) m.setAttribute('port', str(t[1])) m.setAttribute('kind', t[2]) m.setAttribute('protocol', t[3]) r.append(m) return r
def createAttNodes(self, ancestor, attList, parentName): """Returns minidom structure of attributes""" global conflicts attNodes = [] for att in attList: # print(self.existedAttC) if conflicts and self.conflictExists: if self.canExcludeMember(True, parentName, att.name): continue if att.name not in self.existedAtt: self.existedAtt.append(att.name) aTag = Document().createElement("attribute") aTag.setAttribute("name", att.name) aTag.setAttribute("type", att.dataType) aTag.setAttribute("scope", att.scope) if ancestor: fr = Document().createElement("from") fr.setAttribute("name", parentName) aTag.appendChild(fr) attNodes.append(aTag) return attNodes
def xml(self): """ It returns xml.dom.minidom.Element representation of this Module. """ modXML = Document().createElement("Module") modXML.setAttribute("name", "{0}".format(self.label)) modXML.setAttribute("id", "{0}".format(self.id)) modXML.setAttribute("x", "{0}".format(self.gmodule.x())) modXML.setAttribute("y", "{0}".format(self.gmodule.y())) modXML.appendChild( Document().createTextNode("{0}".format(self.description)) ) for tag in self.tags: t = Document().createElement("tag") t.appendChild( Document().createTextNode( "{0}".format(tag) ) ) modXML.appendChild(t) for port in self._ports.values(): modXML.appendChild(port.xml()) return modXML
def xml(self): """ It returns xml.dom.minidom.Element representation of this Module. """ modXML = Document().createElement("Module") modXML.setAttribute("name", "{0}".format(self.label)) modXML.setAttribute("id", "{0}".format(self.id)) modXML.setAttribute("x", "{0}".format(self.gmodule.x())) modXML.setAttribute("y", "{0}".format(self.gmodule.y())) modXML.appendChild(Document().createTextNode("{0}".format( self.description))) for tag in self.tags: t = Document().createElement("tag") t.appendChild(Document().createTextNode("{0}".format(tag))) modXML.appendChild(t) for port in self._ports.values(): modXML.appendChild(port.xml()) return modXML
def createMethodNodes(self, ancestor, mList, classInst): """Returns minidom structure of methods""" mNodes = [] for m in mList: if conflicts and self.conflictExists: if self.canExcludeMember(False, classInst.name, [m.name, m.argumentType]): continue if [m.name, m.argumentType] not in self.existedM: self.existedM.append([m.name, m.argumentType]) mTag = Document().createElement("method") mTag.setAttribute("name", m.name) mTag.setAttribute("type", m.dataType) mTag.setAttribute("scope", m.scope) if m.virtualPure is not None: virtual = Document().createElement("virtual") virtual.setAttribute("pure", m.virtualPure) mTag.appendChild(virtual) if ancestor: fr = Document().createElement("from") fr.setAttribute("name", classInst.name) mTag.appendChild(fr) argTag = Document().createElement("arguments") for i in range(len(m.argumentType)): arg = Document().createElement("argument") arg.setAttribute("name", m.argumentName[i]) arg.setAttribute("type", m.argumentType[i]) argTag.appendChild(arg) mTag.appendChild(argTag) mNodes.append(mTag) return mNodes
def printConflictMembers(self): """Returns minidom structure of conflict members""" conflictTag = Document().createElement("conflicts") for member in self.existedAttC[0::2]: memTag = Document().createElement("member") memTag.setAttribute("name", member) for className in self.existedAttC[self.existedAttC.index(member)+1]: clTag = Document().createElement("class") clTag.setAttribute("name", className) cl = self.findClass(className) CMember = cl.findAttribute(member) if CMember: # it's attribute att = Document().createElement("attribute") else: # it's method CMember = cl.findMethod(member) att = Document().createElement("method") if CMember.virtualPure is not None: virtual = Document().createElement("virtual") virtual.setAttribute("pure", CMember.virtualPure) att.appendChild(virtual) args = Document().createElement("arguments") for i in range(len(CMember.argumentType)): arg = Document().createElement("argument") arg.setAttribute("name", CMember.argumentName[i]) arg.setAttribute("type", CMember.argumentType[i]) args.appendChild(arg) att.appendChild(args) accessTag = Document().createElement(CMember.privacy) att.setAttribute("name", CMember.name) att.setAttribute("type", CMember.dataType) att.setAttribute("scope", CMember.scope) accessTag.appendChild(att) clTag.appendChild(accessTag) memTag.appendChild(clTag) conflictTag.appendChild(memTag) return conflictTag
def xml(self): """ It returns xml.dom.minidom.Element representation of this Module. """ portXML = Document().createElement("Port") portXML.setAttribute("name", self.name) portXML.setAttribute("id", "{0}".format(self.id)) portXML.setAttribute("type", "{0}".format(self.type)) portXML.setAttribute("should_be_set", "{0}".format(self.setIt)) portXML.setAttribute("porttype", "{0}".format(self.portType)) portXML.setAttribute("optional", "{0}".format(self.optional)) portXML.setAttribute("default_value", "{0}".format(self.defaultValue)) # according to type of parameter expression of value should changing? portXML.setAttribute("value", "{0}".format(self._value)) portXML.setAttribute("moduleID", "{0}".format(self.moduleId)) portXML.setAttribute("connected", "{0}".format(self.isConnected())) # portXML.setAttribute("setIt", "{0}".format(self.setIt)) if self.type is processing.parameters.ChoiceParameter: portXML.setAttribute("choices", "{0}".format(self._data)) try: portXML.setAttribute("alternative_name", "{0}".format(self.alternativeName)) except: pass portXML.appendChild(Document().createTextNode("{0}".format( self.description))) return portXML
def printConflictMembers(self): """Returns minidom structure of conflict members""" conflictTag = Document().createElement("conflicts") for member in self.existedAttC[0::2]: memTag = Document().createElement("member") memTag.setAttribute("name", member) for className in self.existedAttC[self.existedAttC.index(member) + 1]: clTag = Document().createElement("class") clTag.setAttribute("name", className) cl = self.findClass(className) CMember = cl.findAttribute(member) if CMember: # it's attribute att = Document().createElement("attribute") else: # it's method CMember = cl.findMethod(member) att = Document().createElement("method") if CMember.virtualPure is not None: virtual = Document().createElement("virtual") virtual.setAttribute("pure", CMember.virtualPure) att.appendChild(virtual) args = Document().createElement("arguments") for i in range(len(CMember.argumentType)): arg = Document().createElement("argument") arg.setAttribute("name", CMember.argumentName[i]) arg.setAttribute("type", CMember.argumentType[i]) args.appendChild(arg) att.appendChild(args) accessTag = Document().createElement(CMember.privacy) att.setAttribute("name", CMember.name) att.setAttribute("type", CMember.dataType) att.setAttribute("scope", CMember.scope) accessTag.appendChild(att) clTag.appendChild(accessTag) memTag.appendChild(clTag) conflictTag.appendChild(memTag) return conflictTag
def get_dom(element, **kwargs): """ Given a tag, returns a new dom element for that tag """ from xml.dom.minidom import Document dom = Document().createElement(element) for key in kwargs: dom.setAttribute(key, kwargs[key]) return dom
def xml(self): """ It returns xml.dom.minidom.Element representation of this Module. """ portXML = Document().createElement("Port") portXML.setAttribute("name", self.name) portXML.setAttribute( "id", "{0}".format(self.id) ) portXML.setAttribute("type", "{0}".format(self.type)) portXML.setAttribute("should_be_set", "{0}".format(self.setIt)) portXML.setAttribute("porttype", "{0}".format(self.portType)) portXML.setAttribute("optional", "{0}".format(self.optional)) portXML.setAttribute("default_value", "{0}".format(self.defaultValue)) # according to type of parameter expression of value should changing? portXML.setAttribute("value", "{0}".format(self._value)) portXML.setAttribute("moduleID", "{0}".format(self.moduleId)) portXML.setAttribute("connected", "{0}".format(self.isConnected())) # portXML.setAttribute("setIt", "{0}".format(self.setIt)) if self.type is processing.parameters.ChoiceParameter: portXML.setAttribute("choices", "{0}".format(self._data) ) try: portXML.setAttribute("alternative_name", "{0}".format(self.alternativeName) ) except: pass portXML.appendChild( Document().createTextNode("{0}".format(self.description)) ) return portXML