[Tutor] Help with Elementtree ...how to access the attributes..

doug shawhan doug.shawhan at gmail.com
Mon Nov 13 16:06:42 CET 2006


Oho! Thanks, Kent (and everyone else.) That clears up some things. The link
has some embarassment reducing info as well. :-)

On 11/11/06, Kent Johnson <kent37 at tds.net> wrote:
>
> doug shawhan wrote:
> > I'm having some difficulties with elementtree as well.
> >
> > I'm attempting to parse a fairly sizeable xml file (it's the ebay
> > "category tree" report. I've cached a copy at
> > http://www.crackrabbit.com/misc/CatTree.xml). 900K or so! :-)
>
> > I've made a smaller version that I could easily get me brain around:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <GetCategoriesResponse xmlns="urn:ebay:apis:eBLBaseComponents">
> >     <Timestamp>2006-11-07T07:45:40.908Z</Timestamp>
> >     <Ack>Success</Ack>
> >     <Version>485</Version>
> >     <Build>e485_core_Bundled_3782281_R1</Build>
> >     <CategoryArray>
> >         <Category>
> >             <BestOfferEnabled>true</BestOfferEnabled>
> >             <CategoryID>6000</CategoryID>
> >             <CategoryLevel>1</CategoryLevel>
> >             <CategoryName>eBay Motors</CategoryName>
> >             <CategoryParentID>6000</CategoryParentID>
> >             <Expired>false</Expired>
> >             <IntlAutosFixedCat>false</IntlAutosFixedCat>
> >             <LeafCategory>false</LeafCategory>
> >             <Virtual>false</Virtual>
> >             <ORPA>false</ORPA>
> >             <LSD>true</LSD>
> >         </Category>
> >     </CategoryArray>
> > </GetCategoriesResponse>
> >
> > which also seems to parse cleanly and appears to be similar to what
> > Asraramed had constructed, but still does not yeild any results no
> > matter which element I attempt to find with findall().
> >
> > What am I doing wrong? Thanks!
>
> When an XML document is in a namespase, ET includes the name of the
> namespace as part of the element name and you have to include it when
> you use findall().
>
> Try categories =
> tree.findall("{urn:ebay:apis:eBLBaseComponents}CategoryArray")
>
> http://effbot.org/zone/element.htm#xml-namespaces
>
> Kent
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061113/dc5741da/attachment.htm 


More information about the Tutor mailing list