예제 #1
0
    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)
예제 #2
0
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()
예제 #3
0
파일: HtmlParser.py 프로젝트: einaru/luma
    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)