I'm trying to get this thing working. I have a XML file and I need to filter the element 'title' using XPath. Afterwards I need to copy everything from under the C element to an external file, but that's not the point right now. I need to get this running using the xml.etree.cElementTree or xml.etree.ElementTree. I have already read a bunch of posts here on stackoverflow and also on other site's and got stuck. Soo.. First the XML structure:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<delivery xmlns="http://url" publicationdate="2013-08-28T09:10:32Z">
<A>
<B>
<C>
<Cid>XXXXXXXXX</Cid>
<cref>111111-2222222</cref>
<D>
<E/>
<F/>
<G/>
<H>
<Href>XXXXXXXXXXXX</Href>
<hcont name="XXXXXX" country="EN"/>
</H>
<I/>
<J/>
<K>XXXXXXXXX</K>
<oldK>XXXXXXX</oldK>
<title>
<content lang="en">TITLE</content>
</title>
<L>
<isL>false</isL>
</L>
</D>
<M>
<startTime>2013-08-28T03:00:00Z</startTime>
<endTime>2013-08-29T00:58:00Z</endTime>
</M>
</C>
</B>
</A>
</delivery>
I can't even get to find the Cid element by XPath. The script keeps returning 'None' or [] or just nothing.
import xml.etree.ElementTree as ET
doc = ET.ElementTree(file='short.xml')
for x in doc.findall('./A/B/C'):
print x.get('Cid').text
This one returns nothing. How to get this working? How to 'find' even the Cid element?