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 Dm...@toyota.com.au on 2004/06/28 02:22:50 UTC
xpath error in selectPath? "Path must select only elements and attributes"
hey all,
not sure if this is my lack of understanding, or a limitation in xmlbeans,
or something completely different. running xmlbeans from bea that shipped
with 8.1SP2.
Consider the following code:
public static void main(String[] args) throws Exception
{
XmlObject xml =
XmlObject.Factory.parse("<foo><bar>0001237843</bar></foo>");
// String text =
xml.selectPath("./foo/bar")[0].newCursor().getTextValue();
String text =
xml.selectPath("./foo/bar/text()")[0].newCursor().getTextValue();
System.out.println("text = " + text);
}
the commented out line works fine. However, the code as it stands throws
the following exception:
com.bea.xml.XmlRuntimeException: Path must select only elements and
attributes
at
com.bea.xbean.values.XmlObjectBase.selectPath(Ljava.lang.String;Lcom.bea.x
ml.XmlOptions;)[Lcom.bea.xml.XmlObject;(XmlObjectBase.java:449)
at
com.bea.xbean.values.XmlObjectBase.selectPath(Ljava.lang.String;)[Lcom.bea
.xml.XmlObject;(XmlObjectBase.java:421)
at
com.toyota.barossa.AuditTest.main([Ljava.lang.String;)V(AuditTest.java:33)
at
COM.jrockit.reflect.NativeMethodInvoker.invoke0(ILjava.lang.Object;[Ljava.
lang.Object;)Ljava.lang.Object;(Native Method)
at
COM.jrockit.reflect.NativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.la
ng.Object;)Ljava.lang.Object;(Unknown Source)
at
java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Lja
va.lang.Object;(Unknown Source)
at
com.intellij.rt.execution.application.AppMain.main([Ljava.lang.String;)V(U
nknown Source)
I had assumed that I'd be able to bang a /number() on the end of my xpath
and trim the leading 0's (damn SAP). Is this a real limitation? From the
xpath spec I get the impression the above is legal...
alternatively, if someone could tell me an easy way of making selectPath
trim the leading 0's that'd be great (o:
cheers
dim