Ruud,
Before I stard researching this, are you using the latest build? If not,
please download it from www.plotnix.com/jxpath/commons-jxpath.zip and try
again. If the problem persists, please let me know - I'll fix it.
Thanks,
- Dmitri
----- Original Message -----
From: "Ruud Diterwich" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, November 10, 2002 4:47 AM
Subject: [JXPath] Variables containing DOM data
> 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:
<mailto:commons-user-unsubscribe@;jakarta.apache.org>
> For additional commands, e-mail:
<mailto:commons-user-help@;jakarta.apache.org>
>
>
>
--
To unsubscribe, e-mail: <mailto:commons-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-user-help@;jakarta.apache.org>