[XML-SIG] Amara xml_xpath() behaviour
Elston, Gareth R
gelston at doosanbabcock.com
Wed Dec 5 11:38:18 CET 2007
Hi,
I'm new to XML and I've just started using Amara - I'm very impressed.
I've been trying to use xml_xpath() on a bindery object itself created
with xml_xpath(). I didn't get what I expected, which may be my
misunderstanding of what xml_xpath() is doing. Here's a short example to
illustrate (I'm using Amara 1.2.0.2 and Python 2.4.3 on Windows XP.):
In [1]: import amara
In [2]: l = amara.parse('file:///F:/lines.xml')
In [3]: print l.xml()
<?xml version="1.0" encoding="UTF-8"?>
<Lines>
<Line>
<Point x2="1.0" x1="1.0"/>
<Point x2="2.0" x1="1.0"/>
</Line>
<Line>
<Point x2="2.0" x1="2.0"/>
<Point x2="3.0" x1="2.0"/>
</Line>
<Line>
<Point x2="3.0" x1="3.0"/>
<Point x2="5.0" x1="3.0"/>
</Line>
</Lines>
In [4]: l.xml_xpath('//Line')
Out[4]:
[<amara.bindery.Line object at 0x015628D0>,
<amara.bindery.Line object at 0x0169E6B0>,
<amara.bindery.Line object at 0x01759D10>]
In [5]: print l.xml_xpath('//Line')[0].xml()
<Line>
<Point x2="1.0" x1="1.0"/>
<Point x2="2.0" x1="1.0"/>
</Line>
In [6]: l.xml_xpath('//Line')[0].xml_xpath('//Point')
Out[6]:
[<amara.bindery.Point object at 0x0169E210>,
<amara.bindery.Point object at 0x0169E250>,
<amara.bindery.Point object at 0x0169EA50>,
<amara.bindery.Point object at 0x01759CD0>,
<amara.bindery.Point object at 0x01759D50>,
<amara.bindery.Point object at 0x01759D90>]
I expected only 2 amara.bindery.Point objects in the last step. Is this
(all 6 Points in the XML data) the expected behaviour?
Thanks,
Gareth
More information about the XML-SIG
mailing list