You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-user@xml.apache.org by Andrew Mould <an...@softsell.com> on 2004/07/15 02:46:30 UTC

Xpath & Namespaces

Hi there,

I'm evaluating XMLBeans but have run into a problem using simple Xpath
expressions with namespaces. 

I'm using the attached schema and xml file from the "Getting Started with
XMLBeans" section of the Apache site
http://xml.apache.org/xmlbeans/docs/guide/conGettingStartedwithXMLBeans.html

Using selectPath with the following strings on the original XML file (which
contains namespaces on each element) I get the following results:

1a:   "declare namespace po = 'http://openuri.org/easypo'"
     +
     "./po:purchase-order/po:line-item"
   -> Returns 2 entries


1b:  "declare namespace po = 'http://openuri.org/easypo' "
     +
     " ./po:purchase-order/po:line-item[2]"
   -> Returns 0 entries

Result 1b would seem to be incorrect.

Changing the XML file to just use a default namespace I get the following:

2a:  "./purchase-order/line-item"
   -> Returns 2 entries

2b:  "./purchase-order/line-item[2]"
   -> Returns 1 entry

Result 2b is now correct. 

So it would appear that using the positional predicate only works with
default namespaces. I'm not sure if I'm doing something wrong, or whether
this is something fixable or what.

Thanks in advance for any help.

- Andrew

Andrew Mould
   Ascert, LLC  415 339-8500 x108.  www.ascert.com
   (Ascert is the parent company of SoftSell Business Systems)