commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitri Plotnikov <dplot...@yahoo.com>
Subject Re: [JXPath] Variables containing DOM data
Date Mon, 02 Dec 2002 21:00:21 GMT
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 <rditerwich@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:  
> <mailto:commons-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:commons-user-help@jakarta.apache.org>
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

Mime
View raw message