Hi Patrizio, I've attached the source I used to run through the your xpath. I am getting a results back from this xpath/xquery statement. I'm curious if all of the required jars are on your path? Here is what my cmd to run the file looked like, it includes ALL of the jars (ie, more than required): D:\svn\apache\xmlbeans\trunk\repro\xpaths>java -classpath ..\..\build\lib\xbean. jar;..\..\build\lib\jsr173_1.0_api.jar;..\..\build\lib\saxon8.jar;..\..\build\li b\resolver.jar;..\..\build\lib\saxon8-dom.jar;..\..\build\lib\xbean_xpath.jar;.. \..\build\lib\xmlpublic.jar;. XPathRepro
Here is the output I get from running the attached file: D:\svn\apache\xmlbeans\trunk\repro\xpaths>java -classpath ..\..\build\lib\xbean. jar;..\..\build\lib\jsr173_1.0_api.jar;..\..\build\lib\saxon8.jar;..\..\build\li b\resolver.jar;..\..\build\lib\saxon8-dom.jar;..\..\build\lib\xbean_xpath.jar;.. \..\build\lib\xmlpublic.jar;. XPathRepro <bs:bookstore xmlns:bs="http://www.bsource.ch/bs"> <book> <id>1</id> <author>author1</author> <title>title1</title> </book> <book> <id>2</id> <author>author2</author> <title>title2</title> </book> </bs:bookstore> START - PRINTING ELEMENTS ELEMENT[0]-<xml-fragment xmlns:bs="http://www.bsource.ch/bs">author2</xml-fragme nt> END - PRINTING ELEMENTS Can you see if you get the same thing? Thanks, -Jacob Danner On 4/17/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Hi Jacob,
I've added the suggested line:
private final static String namespace =
"http://www.bsource.ch/bs";
private final static String namespaceDeclaration = "declare namespace bs='" +
namespace + "';";
public void setValue (String path, String value) throws BookstoreException
{
XmlObject[] elems = null;
try
{
XmlOptions opts = new XmlOptions();
opts.setSavePrettyPrint();
opts.setSavePrettyPrintIndent(4);
System.out.println(document.xmlText(opts));
elems = document.selectPath(namespaceDeclaration +
"$this/bs:bookstore/book[author='author2']/author");
}
catch (Exception e)
{
throw new BookstoreException(e.getMessage());
}
if (elems.length == 0)
throw new BookstoreException("no result found for the given path
expression");
The output:
<bs:bookstore xmlns:bs="http://www.bsource.ch/bs">
<book>
<id>1</id>
<author>author1</author>
<title>title1</title>
</book>
<book>
<id>2</id>
<author>author2</author>
<title>title2</title>
</book>
</bs:bookstore>
test.BookstoreException: no result found for the given path expression
at test.Bookstore.setValue(Bookstore.java:74)
at test.Bookstore.main(Bookstore.java:108)
Regards
Patrizio
-----Original Message-----
From: Jacob Danner [mailto:[EMAIL PROTECTED]
Sent: lunedì, 16. aprile 2007 18:26
To: [email protected]
Subject: Re: troubles executing XmlObject.selectPath
Can we see the output of the following:
XmlObject[] elems = null;
// ADD this line
System.out.println(document.xmlText());
elems = document.selectPath(namespaceDeclaration +
"$this/bs:bookstore/book[author='author2']/author");
On 4/16/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Ciao Radu,
>
> thanks for the suggestion but:
>
> private final static String namespace =
"http://www.bsource.ch/bs";
> private final static String namespaceDeclaration = "declare namespace bs='" +
namespace + "';";
> ...
> XmlObject[] elems = null;
> elems = document.selectPath(namespaceDeclaration +
"$this/bs:bookstore/book[author='author2']/author");
>
> the same error: elems length array is 0 !
>
> Regards
> Patrizio
>
>
> -----Original Message-----
> From: Radu Preotiuc-Pietro [mailto:[EMAIL PROTECTED]
> Sent: venerdì, 13. aprile 2007 23:02
> To: [email protected]
> Subject: Re: troubles executing XmlObject.selectPath
>
>
> Can I suggest using "declare namespace" to bind the prefix "bs" to the
> current namespace inside the XPath? I doubt it would know what the
> prefix means....
>
> Radu
>
> On Fri, 2007-04-13 at 16:20 +0200, [EMAIL PROTECTED] wrote:
> > Hi all,
> >
> > I'm using xmlbeans-2.2.0 and saxonb8-6-1 and I'm trying to use
> > the XmlObject.selectPath function.
> >
> > Here my xml document:
> >
> > <bs:bookstore xmlns:bs="http://www.bsource.ch/bs">
> > <book>
> > <id>1</id>
> > <author>author1</author>
> > <title>title1</title>
> > </book>
> > <book>
> > <id>2</id>
> > <author>author2</author>
> > <title>title2</title>
> > </book>
> > </bs:bookstore>
> >
> > generated using XmlCursor object in the following way:
> >
> > 1) in Bookstore constructor
> >
> > document = XmlObject.Factory.newInstance();
> > cursor = document.newCursor();
> > cursor.toNextToken();
> > cursor.beginElement("bookstore", namespace);
> >
> > 2) when I add a book to my bookstore object
> >
> > public void add(Book book) throws BookstoreException
> > {
> > if (book == null) throw new ...
> > if (document == null) throw new ...
> >
> > id++;
> > book.setId("" + id);
> >
> > cursor.beginElement("book");
> > cursor.insertElementWithText("id", book.getId());
> > cursor.insertElementWithText("author", book.getAuthor());
> > cursor.insertElementWithText("title", book.getTitle());
> > cursor.toNextToken();
> > }
> >
> > Now I'm trying to run the following piece of code:
> >
> > XmlObject[] elems = null;
> > ...
> > elems =
> > document.selectPath("$this/bs:bookstore/book[author='author2']/author");
> > if (elems.length == 0)
> > throw new BookstoreException("no result found for the given path
> > expression");
> >
> > but selectPath returns zero elems !
> > I've checked the xpath expression
> > (/bs:bookstore/book[author='author2']/author) with XMLSpy against the
> > same xml document and the xpath expression seems to be correct ... so
> > I don't understand because selectPath fails to return the results.
> >
> > Could you give me please some hints on that ?
> >
> > Regards
> > Patrizio
> >
> > IMPORTANT:
> > This e-mail transmission is intended for the named
> > addressee(s)only.
> > Its contents are private, confidential and protected
> > from disclosure and should not be read, copied or
> > disclosed by any other person.
> > If you are not the intended recipient, we kindly ask
> > you to notify the sender immediately by telephone
> > (+41 (0)58 806 50 00), to redirect the message to the
> > account "[EMAIL PROTECTED]" and to delete this e-mail.
> > E-mail transmissions may be intercepted, altered or
> > read by unauthorized persons and may contain viruses.
> > Therefore, it is recommended that you use regular mail
> > or courier services for any information intended to be
> > confidential. However, by sending us messages through
> > e-mail, you authorize and instruct us to correspond by
> > e-mail in the relevant matter.
> > Thank you.
> >
> >
> >
>
> Notice: This email message, together with any attachments, may contain
information of BEA Systems, Inc., its subsidiaries and affiliated entities,
that may be confidential, proprietary, copyrighted and/or legally privileged,
and is intended solely for the use of the individual or entity named in this
message. If you are not the intended recipient, and have received this message in
error, please immediately return this by email and then delete it.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> IMPORTANT:
> This e-mail transmission is intended for the named
> addressee(s)only.
> Its contents are private, confidential and protected
> from disclosure and should not be read, copied or
> disclosed by any other person.
> If you are not the intended recipient, we kindly ask
> you to notify the sender immediately by telephone
> (+41 (0)58 806 50 00), to redirect the message to the
> account "[EMAIL PROTECTED]" and to delete this e-mail.
> E-mail transmissions may be intercepted, altered or
> read by unauthorized persons and may contain viruses.
> Therefore, it is recommended that you use regular mail
> or courier services for any information intended to be
> confidential. However, by sending us messages through
> e-mail, you authorize and instruct us to correspond by
> e-mail in the relevant matter.
> Thank you.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
IMPORTANT:
This e-mail transmission is intended for the named
addressee(s)only.
Its contents are private, confidential and protected
from disclosure and should not be read, copied or
disclosed by any other person.
If you are not the intended recipient, we kindly ask
you to notify the sender immediately by telephone
(+41 (0)58 806 50 00), to redirect the message to the
account "[EMAIL PROTECTED]" and to delete this e-mail.
E-mail transmissions may be intercepted, altered or
read by unauthorized persons and may contain viruses.
Therefore, it is recommended that you use regular mail
or courier services for any information intended to be
confidential. However, by sending us messages through
e-mail, you authorize and instruct us to correspond by
e-mail in the relevant matter.
Thank you.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
XPathRepro.java
Description: Binary data
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

