List Info

Thread: troubles executing XmlObject.selectPath




troubles executing XmlObject.selectPath
country flaguser name
Switzerland
2007-04-13 09:20:45
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>
 &nbsp; <id&gt;1</id&gt;
 &nbsp; <author>author1</author>
 &nbsp; <title>title1</title&gt;
 </book>
 <book>
 &nbsp; <id&gt;2</id&gt;
 &nbsp; <author>author2</author>
 &nbsp; <title>title2</title&gt;
  </book&gt;
</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
{
 &nbsp; if (book == null) &nbsp; &nbsp; &nbsp;  throw new ...
 &nbsp; if (document == null) throw new ...
 
 &nbsp; id++;
 &nbsp; book.setId("" + id);
 
 &nbsp; cursor.beginElement("book");
 &nbsp; cursor.insertElementWithText("id", book.getId());
 &nbsp; cursor.insertElementWithText("author", book.getAuthor());
 &nbsp; cursor.insertElementWithText("title", book.getTitle());
 &nbsp; 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)
 &nbsp; 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
 
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )