[Tutor] Help with Elementtree ...how to access the attributes..
Kent Johnson
kent37 at tds.net
Sat Nov 11 13:28:20 CET 2006
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
More information about the Tutor
mailing list