I am trying to solve a problem/implementation using xpath. Using code (python) is of course also possible, but I prefer to do it in xpath if possible
Right, say I’ve got a xml file that looks a bit like this:
<?xml version="1.0" encoding="UTF-8"?>
<dir>
<results>
<entrylist>
<entry>
<type>document</type>
<name>a file name 1</name>
<date>2012-01-01</date>
<size>65421316516</size>
</entry>
<entry>
<type>document</type>
<name>a file name 2</name>
<date>2012-01-02</date>
<size>6542131</size>
</entry>
<entry>
<type>document</type>
<name>a file name 3</name>
<date>2012-01-03</date>
<size>654</size>
</entry>
</entrylist>
</results>
</dir>
I can not change the layout of the xml
From this xml I need to extract the name and date of each entry. I somewhat prefer them to be grouped together without the type/size in the result returned by my xpath function.
So to sum it up, I need(want) an output that looks a bit like this:
[0]
| – name: a file name 1
| – date: 2012-01-01[1]
| – name: a file name 2
| – date: 2012-01-02
etc
Is this in any possible way even possible? or I am I stuck with just using a xmldocument parser in python? (using etree from lxml)
I’m not sure this is what you would like, but:
AFAIK, XPath is for selecting nodes, not combining them, so I don’t think it can do all of the job for you.