Hi Jacob,

I was using eclipse but just now I switched to command line as your test, to 
see if there is any difference.

So:

1) at source level the same changes as you

        try {
            //XmlObject _document = XmlObject.Factory.parse(docContent);
            XmlObject document = XPathRepro.createDocument();

2) compilation

C:\projects\workspace\xml\xmlcursor>javac -d classes -classpath 
.\lib\xbean.jar;.\lib\jsr173_1.0_api.jar;.\lib\resolver.jar;.\lib\saxon8.jar;.\lib\saxon8-dom.jar;.\lib\xbean_xpath.jar;.\lib\xmlpublic.jar;.
 src\test\XPathRepro.java

C:\projects\workspace\xml\xmlcursor>dir /s classes
...
 Directory of C:\projects\workspace\xml\xmlcursor\classes\test
19.04.2007  11:56             3'002 XPathRepro.class

About the jars used:

C:\projects\workspace\xml\xmlcursor\lib>dir
12.06.2006  12:45            23'630 jsr173_1.0_api.jar
12.06.2006  12:45            60'047 resolver.jar
22.11.2005  14:03            43'963 saxon8-dom.jar
22.11.2005  14:03         3'118'502 saxon8.jar
12.06.2006  12:45         2'664'574 xbean.jar
12.06.2006  12:45             5'578 xbean_xpath.jar
12.06.2006  12:45           429'483 xmlpublic.jar

Are you using the same ? (from saxonb8-6-1, xmlbeans-2.2.0)

3) running

C:\projects\workspace\xml\xmlcursor>java -classpath 
.\lib\xbean.jar;.\lib\jsr173_1.0_api.jar;.\lib\resolver.jar;.\lib\saxon8.jar;.\lib\saxon8-dom.jar;.\lib\xbean_xpath.jar;.\lib\xmlpublic.jar;.\classes
 test.XPathRepro
### createDocument:
<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>
### main:
<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>
Exception in thread "main" java.lang.Exception: Unsupported node type in DOM! 
11 instance [EMAIL PROTECTED]
        at test.XPathRepro.main(XPathRepro.java:45)

I don't understand why ...

About your additional question, there is no schema (XSD) behind it.
Just I started to use xmlbeans framework and I'm interested on using XmlObject 
& XmlCursor classes. 
So I tried to use XmlCursor to build a new xml document and document.selectPath 
to extract values (and then changing some values in the xml document ...).

The full stack trace of the error is:

</bs:bookstore>
java.lang.IllegalArgumentException: Unsupported node type in DOM! 11 instance 
[EMAIL PROTECTED]
        at net.sf.saxon.dom.NodeWrapper.makeWrapper(NodeWrapper.java:107)
        at net.sf.saxon.dom.NodeWrapper.makeWrapper(NodeWrapper.java:63)
        at net.sf.saxon.dom.DocumentWrapper.wrap(DocumentWrapper.java:57)
        at net.sf.saxon.dom.DOMObjectModel.unravel(DOMObjectModel.java:140)
        at net.sf.saxon.Controller.unravel(Controller.java:1291)
        at net.sf.saxon.value.Value.convertToBestFit(Value.java:1025)
        at net.sf.saxon.value.Value.convertJavaObjectToXPath(Value.java:865)
        at net.sf.saxon.trans.Variable.setValue(Variable.java:119)
        at 
org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath.selectNodes(XBeansXPath.java:95)
        at 
org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath.selectPath(XBeansXPath.java:108)
        at 
org.apache.xmlbeans.impl.store.Path$SaxonPathImpl$SaxonPathEngine.next(Path.java:496)
        at org.apache.xmlbeans.impl.store.Cursor._toSelection(Cursor.java:931)
        at 
org.apache.xmlbeans.impl.store.Cursor._toNextSelection(Cursor.java:920)
        at 
org.apache.xmlbeans.impl.store.Cursor._hasNextSelection(Cursor.java:912)
        at 
org.apache.xmlbeans.impl.store.Cursor.hasNextSelection(Cursor.java:2652)
        at 
org.apache.xmlbeans.impl.values.XmlObjectBase.selectPath(XmlObjectBase.java:433)
        at 
org.apache.xmlbeans.impl.values.XmlObjectBase.selectPath(XmlObjectBase.java:415)
        at test.XPathRepro.main(XPathRepro.java:36)

Thanks again for the time you're spending around my troubles.

Regards
Patrizio


-----Original Message-----
From: Jacob Danner [mailto:[EMAIL PROTECTED] 
Sent: mercoledì, 18. aprile 2007 22:43
To: user@xmlbeans.apache.org
Subject: Re: troubles executing XmlObject.selectPath


Hi Patrizio,
I'm not sure where you are getting that error from. When I run the src
you gave me (with only textual and package difference) everything
works fine for me.
My changes were removing the package declaration and commenting out
the other XmlObject . For Example,
// XmlObject _document = XmlObject.Factory.parse(docContent);

My output is below.

What kind of environment are you running in. Is it an IDE?
Also, for general programming purposes, it seems like your XML
instance has some kind of shape, Is there a schema (XSD) behind it. If
there is you could just use the simple POJO (getters/setters) API for
manipulating this XML.

Thanks,
-Jacobd

OUTPUT:
D:\svn\xmlbeans\trunk\reproDir>javac -classpath ..\build\lib\xbean.jar;..\build\
lib\jsr173_1.0_api.jar;..\build\lib\resolver.jar;..\build\lib\saxon8.jar;..\buil
d\lib\saxon8-dom.jar;..\build\lib\xbean_xpath.jar;..\build\lib\xmlpublic.jar;. X
PathRepro.java

D:\svn\xmlbeans\trunk\reproDir>java -classpath ..\build\lib\xbean.jar;..\build\l
ib\jsr173_1.0_api.jar;..\build\lib\resolver.jar;..\build\lib\saxon8.jar;..\build
\lib\saxon8-dom.jar;..\build\lib\xbean_xpath.jar;..\build\lib\xmlpublic.jar;. XP
athRepro
### createDocument:
<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>
### main:
<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>author2</xml-fragment>
END - PRINTING ELEMENTS


On 4/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Hi Jacob,
>
> thanks a lot for your support.
>
> Two 'strange' thinks that I've noticed:
>
> 1) your example (and now also my example) is working simply adding only one 
> extra jar: saxon8-dom.jar.
> That is at the end the jars in my path are:
>
> saxon8.jar
> xbean_xpath.jar
> jsr173_1.0_api.jar
> xbean.jar
> saxon8-dom.jar
>
> and also your example works even with only these jars.
>
> But if I remove only saxon8-dom.jar I don't get any error but simply I see 
> the exception raised from our code:
>
> java.lang.Exception: no result found for the given path expression
>         at test.XPathRepro.main(XPathRepro.java:47)
>
> so I was expecting some other specific error from saxon distribution instead 
> of an empty XmlObject[] elems array.
>
> In any case I'll use the above listed jars.
>
> 2) I added a small change to your example:
>
> - a method for building the XmlObject instead of using the static docContent 
> string
>
>     public static XmlObject createDocument()
>     {
>         XmlObject document = XmlObject.Factory.newInstance();
>         XmlCursor cursor   = document.newCursor();
>         cursor.toNextToken();
>         cursor.beginElement("bookstore", namespace);
>                 cursor.beginElement("book");
>                 cursor.insertElementWithText("id",     "1");
>                 cursor.insertElementWithText("author", "author1");
>                 cursor.insertElementWithText("title",  "title1");
>                 cursor.toNextToken();
>                 cursor.beginElement("book");
>                 cursor.insertElementWithText("id",     "2");
>                 cursor.insertElementWithText("author", "author2");
>                 cursor.insertElementWithText("title",  "title2");
>                 cursor.toNextToken();
>
>         XmlOptions opts = new XmlOptions();
>         opts.setSavePrettyPrint();
>         opts.setSavePrettyPrintIndent(4);
>         System.out.println("### createDocument:\n" + document.xmlText(opts));
>         return document;
>     }
>
> - in your main
>
>         try {
>             XmlObject _document = XmlObject.Factory.parse(docContent);
>             XmlObject document = XPathRepro.createDocument();
>
> but now the error is:
>
> java.lang.Exception: Unsupported node type in DOM! 11 instance [EMAIL 
> PROTECTED]
>         at test.XPathRepro.main(XPathRepro.java:45)
>
> I compared the XPathRepro.createDocument to the docContent document but they 
> are equal.
>
> (the same if I add the other jars resolver.jar and xmlpublic.jar)
> I've attached your changed XPathRepro.java class.
>
> Thanks again
> Patrizio
>
>
>
>
> -----Original Message-----
> From: Jacob Danner [mailto:[EMAIL PROTECTED]
> Sent: martedì, 17. aprile 2007 18:06
> To: user@xmlbeans.apache.org
> Subject: Re: troubles executing XmlObject.selectPath
>
>
> 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: user@xmlbeans.apache.org
> > 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: user@xmlbeans.apache.org
> > > 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]
> >
> >
>
>
> 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.

Attachment: XPathRepro.java
Description: XPathRepro.java

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to