[PyQt] Kind of newbie question about reading XML file

Detlev Offenbach detlev at die-offenbachs.de
Fri Dec 5 17:47:15 GMT 2008


Hi,

why not use the SAX based interface? I find the SAX approach easier to 
understand and to implement.

Regards,
Detlev

On Freitag, 5. Dezember 2008, Gustavo A. Díaz wrote:
> Hi guys,
>
> I am facing a problem when how to read a XML with tags, and sub tags. Like
> for example:
>
> <FirstTag>
>     <SecondTag>
>         <data1>text</data1>
>         <data2<text</data2>
>     </SecondTag>
> <FristTag>
>
> The thing is that before I was  using just one tag like:
>
> <FirstTag>
>     <data1>text</data1>
>     <data2<text</data2>
> <FristTag>
>
> and I've found examples (of course in Qt docs) of how to achieve the
> reading of this example of XML. But now i don't know how. And most cause i
> am still newbie, and more working with XML files.
>
> So, my old code is:
>
> self.file = QFile(PREFERENCES_FILE)
> self.file.open(QIODevice.ReadOnly)
> self.doc = QDomDocument("OpenCoffee")
> self.doc.setContent(self.file)
> self.file.close()
>
> self.docElem = self.doc.documentElement()
>         self.node = self.docElem.firstChild()
>
>         while (self.node.isNull() == False):
>             self.element = self.node.toElement()
>
>             if (self.element.isNull() == False):
>                 if (self.element.tagName().contains("systemTray")):.... etc
> etc.
>
> But of course this will not work now, since i have to read trwo 2 tags
> before searching the elements inside them.
> Can someone give my a hand on this? i've droped this part of the code in my
> app since i dont find any usefull clear example of how to do it.
>
> Ataching my XML file.
>
> Thanks a Lot.



-- 
Detlev Offenbach
detlev at die-offenbachs.de



More information about the PyQt mailing list