You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Dmitri Plotnikov <dp...@yahoo.com> on 2002/12/02 22:00:21 UTC
Re: [JXPath] Variables containing DOM data
Ruud,
I recently made some changes in JXPath that are supposed to make this
issue go away. When you have a chance, could you try and let me know?
Thanks,
- Dmitri
--- Ruud Diterwich <rd...@cedron.com> wrote:
> Hi all,
>
> I'm experiencing problems with variables that have been assigned DOM
> nodes. In particular, the JXPathContext.getValue method ends up
> calling
> Element.toString, which does not result in the value of a DOM node
> according to the XPath spec.
>
> public void testJXPathDOMVariable() throws Exception {
>
> // read book xml
> String xmlString = "<book>This is my book</book>";
> Document doc =
> DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new
> ByteArrayInputStream(xmlString.getBytes()));
> Element book = doc.getDocumentElement();
>
> // evaluate the value of book directly
> JXPathContext context = JXPathContext.newContext(book);
> String value = (String) context.getValue(".",
> String.class);
> System.out.println("value: " + value);
>
> // evaluate the value of book using a variable
> Variables variables = context.getVariables();
> variables.declareVariable("i", book);
> value = (String) context.getValue("$i", String.class);
> System.out.println("value: " + value);
>
> // evaluate the value of book using a variable, second
> attempt
> variables.declareVariable("i", new DOMNodePointer(book,
> Locale.getDefault()));
> value = (String) context.getValue("$i", String.class);
> System.out.println("value: " + value);
> }
>
> result:
>
> value: This is my book
> value: [book: null]
> value:
>
> I expected the second value to be 'This is my book' as well. The
> value
> '[book: null]' is produced by Xerces' DOM.toString method. What am I
> doing wrong?
>
> Ruud Diterwich
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com