Python and XML Help

ookrin ooklah at
Sat Apr 18 03:35:45 CEST 2009

On Apr 15, 9:43 am, Scott David Daniels <Scott.Dani... at Acm.Org> wrote:
> ookrin wrote:
> > .... I am still learning. And it's not that I won't take the advice
> > for using ElementTree, I just currently don't know anything about it.
> > I just didn't want to say, "I have no idea what you're talking about!"
> > to Scott cause I figured that would be rude, but I guess so is not
> > saying anything, sorry. So I'll need to read up on it before I
> > actually try to do anything with that approach.
> > Seeing the errors - I changed the two classes to this:
> >   ... [some code that actually says a _little_ bit about his target] ....
> If you had done a better job of asking your question, you'd have found a
> quick answer.  That is why everyone points people at smartquestions, not
> to pick on them.
> Presuming you have an xml structure like:
>      txt = '''<abc> something <def>
>             <name name='steve' characterID='sid'> Some contents. </name>
>             <name name='stevey' characterID='sidy'>Other contents.</name>
>             </def></abc>'''
>      import xml.etree.ElementTree as ET
>      structure = ET.fromstring(xmls)
>      for node in structure.findall('def/name'):
>          print '%s: %s / %s: %s' % (node.tag, node.attrib['name'],
>                                node.attrib['characterID'], node.text)
> or a file named 'my.xml' with the same contents:
>      import xml.etree.ElementTree as ET
>      structure = ET.parse('my.xml')
>      for node in structure.findall('def/name'):
>          print '%s: %s / %s: %s' % (node.tag, node.attrib['name'],
>                                node.attrib['characterID'], node.text)
> --Scott David Daniels
> Scott.Dani... at Acm.Org

Thanks very much for your patience with me and thanks for the help
This is my end result:

            self.api = apiConnection(self.userID,self.apiKey)
            xmlData = self.api.returnXml()
            if(xmlData != "None"):
                struct = ET.fromstring(xmlData)
                self.charIDs =[]
                for node in struct.findall('result/rowset/row'):
                    char = node.attrib['name']
                    id = node.attrib['characterID']
                    temp = char, id
                    #append them to the variable for later
                #Setup the select window and run it
                #selects which character I want
                self.selectCharUi = selectChar(self,self.charIDs)

                #Get the name that was selected
                self.selectedCharName = self.selectCharUi.returnValue
                #Set the text widget with the name
                #enable the Ok button

It collects the names and IDs, sends them to a pyqt4 window with a
list widget to list the names, a name gets selected and then I get the
name that was selected. Though now that I think about it, maybe using
a dictionary would be better. Elsewhere I gather up the userID, apiID,
characterName and characterID and write it t a file. I hope it doesn't
look too horrible.

John - my programming experience was two semesters of c++ about 6
years ago. Everything else I've learned from the internet.  =/

I'll try to make my questions better next time.


More information about the Python-list mailing list