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>

Reply via email to