def parseHtml(self, htmlTemplate): # reload smartObject each time self.smartObject = self.entryModel.getSmartObject() #TODO remove QString reader = QXmlStreamReader(htmlTemplate) tmpList = [] while not reader.atEnd(): reader.readNext() name = unicode(reader.name().toString()) if reader.isStartElement(): attributes = reader.attributes() if name == "ldapobject": tmpList.append(self.createStringFromTemplate(attributes)) else: if not attributes.isEmpty(): size = attributes.size() list = [] for i in range(0, size): attribute = attributes.at(i) attributeName = unicode( attribute.name().toString()) attributeValue = unicode( attribute.value().toString()) attributeString = '%s="%s"' % (attributeName, attributeValue) list.append(attributeString) attributesString = ' '.join(list) tag = "<%s %s>" % (name, attributesString) tmpList.append(tag) else: tag = "<%s>" % name tmpList.append(tag) elif reader.isEndElement(): if not (name == "ldapobject"): tag = "</%s>" % name tmpList.append(tag) elif reader.isCharacters(): if not (unicode(reader.name()) == "ldapobject"): tmpList.append(unicode(reader.text().toString())) if reader.hasError(): return reader.errorString() return ''.join(tmpList)
class CXmlReading: def __init__(self): self._xmlReader = QXmlStreamReader() def readNext(self): return self._xmlReader.readNext() def atEnd(self): return self._xmlReader.atEnd() def name(self): return self._xmlReader.name() def readElementText(self): return self._xmlReader.readElementText() def isStartElement(self): return self._xmlReader.isStartElement() def isEndElement(self): return self._xmlReader.isEndElement()
def parseHtml(self, htmlTemplate): # reload smartObject each time self.smartObject = self.entryModel.getSmartObject() #TODO remove QString reader = QXmlStreamReader(htmlTemplate) tmpList = [] while not reader.atEnd(): reader.readNext() name = unicode(reader.name().toString()) if reader.isStartElement(): attributes = reader.attributes() if name == "ldapobject": tmpList.append(self.createStringFromTemplate(attributes)) else: if not attributes.isEmpty(): size = attributes.size() list = [] for i in range(0, size): attribute = attributes.at(i) attributeName = unicode(attribute.name().toString()) attributeValue = unicode(attribute.value().toString()) attributeString = '%s="%s"' % (attributeName, attributeValue) list.append(attributeString) attributesString = ' '.join(list) tag = "<%s %s>" % (name, attributesString) tmpList.append(tag) else: tag = "<%s>" % name tmpList.append(tag) elif reader.isEndElement(): if not (name == "ldapobject"): tag = "</%s>" % name tmpList.append(tag) elif reader.isCharacters(): if not (unicode(reader.name()) == "ldapobject"): tmpList.append(unicode(reader.text().toString())) if reader.hasError(): return reader.errorString() return ''.join(tmpList)