2007/12/5, Elston, Gareth R <[EMAIL PROTECTED]>: > 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? >
About XPath: http://www.w3.org/TR/xpath //Point selects all the Point descendants of the document root. l.xml_xpath('//Line')[0].xml_xpath('Point') or better: l.xml_xpath('//Line[1]/Point') But, be care because amara xpath has some problems ordering nodes (see http://lists.fourthought.com/pipermail/4suite/2007-June/008285.html) and it will not be fixed until amara 2.0 -- lm _______________________________________________ XML-SIG maillist - XML-SIG@python.org http://mail.python.org/mailman/listinfo/xml-sig