Return-Path: Delivered-To: apmail-xml-xmlbeans-user-archive@www.apache.org Received: (qmail 29967 invoked from network); 15 Jul 2004 19:21:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 15 Jul 2004 19:21:59 -0000 Received: (qmail 55333 invoked by uid 500); 15 Jul 2004 19:21:58 -0000 Delivered-To: apmail-xml-xmlbeans-user-archive@xml.apache.org Received: (qmail 55296 invoked by uid 500); 15 Jul 2004 19:21:58 -0000 Mailing-List: contact xmlbeans-user-help@xml.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: xmlbeans-user@xml.apache.org Delivered-To: mailing list xmlbeans-user@xml.apache.org Received: (qmail 55283 invoked by uid 99); 15 Jul 2004 19:21:57 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org From: "Andrew Mould" To: Subject: Xpath & Namespaces Date: Thu, 15 Jul 2004 12:21:48 -0700 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0000_01C46A66.4D2E1290" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.4510 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N ------=_NextPart_000_0000_01C46A66.4D2E1290 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi there, I'm evaluating XMLBeans but have run into a problem using simple Xpath expressions with namespaces.=20 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.h= tml 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 =3D 'http://openuri.org/easypo'" + "./po:purchase-order/po:line-item" -> Returns 2 entries 1b: "declare namespace po =3D '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.=20 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) ------=_NextPart_000_0000_01C46A66.4D2E1290 Content-Type: application/octet-stream; name="POTest.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="POTest.java" import java.io.File; import java.io.IOException; import java.math.BigDecimal; import org.apache.xmlbeans.*; import org.openuri.easypo.PurchaseOrderDocument; import org.openuri.easypo.PurchaseOrderDocument.PurchaseOrder; import org.openuri.easypo.LineItem; import org.openuri.easypo.Customer; public class POTest { public static void main( String[] args ) { System.out.println("\n=3D=3D=3D=3D=3D=3D xpath test = =3D=3D=3D=3D=3D=3D=3D"); // Using XML with namespaces on all elements test_xpath(111, "poWithNS.xml", "declare namespace po =3D = 'http://openuri.org/easypo'" + "./po:purchase-order/po:line-item"); test_xpath(112, "poWithNS.xml", "declare namespace po =3D = 'http://openuri.org/easypo' " + " = ./po:purchase-order/po:line-item[2]"); // Using XML without namespaces on elements - using single = default namespace test_xpath(121, "poNoNS.xml", "./purchase-order/line-item"); =20 test_xpath(122, "poNoNS.xml", "./purchase-order/line-item[2]");=20 } private static void show_result(Object[] results) throws Throwable { System.out.println ("Number of results: " + results.length); for (int i =3D 0; i < results.length; i++) { Object node =3D results[i]; System.out.println("=3D> class: "+node.getClass() +", obj: = "+node); } } public static void test_xpath(int id, String xmlFile, String xpath) = { try { = System.out.println("\n=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D = test"+id+" =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"); System.out.println("(File: " + xmlFile + "; Expr: \"" + xpath = + "\")"); XmlObject xmlObj =3D XmlObject.Factory.parse(new = File(xmlFile)); XmlObject[] results =3D xmlObj.selectPath(xpath); show_result(results); } catch (Throwable e) { e.printStackTrace(); } }=20 =20 =20 } ------=_NextPart_000_0000_01C46A66.4D2E1290 Content-Type: text/xml; name="poNoNs.xml" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="poNoNs.xml" Gladys Kravitz
Anytown, PA
2003-01-07T14:16:00-05:00 Burnham's Celestial Handbook, Vol 1 5 21.79 3 Burnham's Celestial Handbook, Vol 2 5 19.89 4 ZipShip 0.74
------=_NextPart_000_0000_01C46A66.4D2E1290 Content-Type: text/xml; name="po.xsd" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="po.xsd" =09 ------=_NextPart_000_0000_01C46A66.4D2E1290 Content-Type: text/xml; name="poWithNS.xml" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="poWithNS.xml" Gladys Kravitz Anytown, PA 2003-01-07T14:16:00-05:00 Burnham's Celestial Handbook, Vol = 1 5 21.79 2 Burnham's Celestial Handbook, Vol = 2 5 19.89 2 ZipShip 0.74 ------=_NextPart_000_0000_01C46A66.4D2E1290 Content-Type: text/plain; charset=us-ascii - --------------------------------------------------------------------- To unsubscribe, e-mail: xmlbeans-user-unsubscribe@xml.apache.org For additional commands, e-mail: xmlbeans-user-help@xml.apache.org Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/ ------=_NextPart_000_0000_01C46A66.4D2E1290--