[XML-SIG] Amara xml_xpath() behaviour

Elston, Gareth R gelston at doosanbabcock.com
Wed Dec 5 11:38:18 CET 2007


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 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"?>
    <Point x2="1.0" x1="1.0"/>
    <Point x2="2.0" x1="1.0"/>
    <Point x2="2.0" x1="2.0"/>
    <Point x2="3.0" x1="2.0"/>
    <Point x2="3.0" x1="3.0"/>
    <Point x2="5.0" x1="3.0"/>

In [4]: l.xml_xpath('//Line')
[<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()
    <Point x2="1.0" x1="1.0"/>
    <Point x2="2.0" x1="1.0"/>

In [6]: l.xml_xpath('//Line')[0].xml_xpath('//Point')
[<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?


More information about the XML-SIG mailing list