short notes is a journal on software, systems, engineering practices among other things.
Copyright © 2002-2006 short notes. All rights reserved. contact address: email to the editor ISSN 1543-6489
short notes |
Tuesday, 18. June 2002
Tuesday 2002-06-18 DevelopmentJXPath - XPath for Java From Jakarta page on JXPath: JXPath applies XPath expressions to graphs of objects of all kinds: JavaBeans, Maps, Servlet contexts, DOM etc, including mixtures thereof. Consider this example: Address address = (Address)JXPathContext.newContext(vendor). getValue("locations[address/zipCode='90210']/address"); This XPath expression is equvalent to the following Java code: Address address = null; Collection locations = vendor.getLocations(); Iterator it = locations.iterator(); while (it.hasNext()){ Location location = (Location)it.next(); String zipCode = location.getAddress().getZipCode(); if (zipCode.equals("90210")){ address = location.getAddress(); break; } }
Some pros and cons: Pro: Code gets shorter. Con: Compiler can't do type checking. Expression is just an embedded string. Pro: Because it's string we can do dynamic queries via file system, telnet, http texts! Con: Security. Pro: Same expression/query language for Java and XML. Con: Why mix oil and water? Pro: XPath can be the universal query language. Con: We live in an interesting time.
NB JXPath is a subset of Jex API.
|
Published since 2002-04-23
Updated: 2010-10-16 Youre not logged in ... Login
about short notes home topics: Development Policy, Process, Mechanism Software Web of Services World
|