dmitri 02/04/10 20:00:32
Modified:jxpath/xdocs users-guide.xml
Log:
Added more text
Revision ChangesPath
1.2 +182 -74 jakarta-commons/jxpath/xdocs/users-guide.xml
Index: users-guide.xml
===
RCS file: /home/cvs/jakarta-commons/jxpath/xdocs/users-guide.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- users-guide.xml 10 Apr 2002 03:40:21 - 1.1
+++ users-guide.xml 11 Apr 2002 03:00:31 - 1.2
@@ -19,14 +19,17 @@
p
If you are not familiar with the XPath syntax, start with
a href=http://www.w3schools.com/xpath;XPath Tutorial by W3Schools/a.br/
- Also see a href=http://www.w3.org/TR/xpath;XML Path Language (XPath)
Version 1.0 /a
+ Also see a href=http://www.w3.org/TR/xpath;XML Path Language (XPath)
Version 1.0 /a -
+ that's the official standard.
/p
p
- You can read and write properties
- of JavaBeans, get and set elements of arrays, collections,
- maps, DOM documents, transparent containers, various context objects
- in Servlets etc.
+ XPath is the official expression language of XSLT. In XSLT you mostly use
+ XPath to access various elements of XML documents. You can do that with
+ JXPath as well. In addition, you can read and write properties of JavaBeans,
get and set
+ elements of arrays, collections, maps, transparent containers, various context
objects
+ in Servlets etc. In other words, JXPath applies the concepts of XPath
+ to alternate object models.
/p
p
@@ -46,8 +49,9 @@
properties.
/p
p
- The interpretation of the xpath syntax in the context of Java object graphs
- is quite intuitive: the child axis of XPath is mapped to JavaBean properties.
+ The interpretation of the XPath syntax in the context of Java object graphs
+ is quite intuitive: the codechild/code axis of XPath is mapped to
+ JavaBean properties.
/p
subsection name=JavaBean Property Access
@@ -71,11 +75,19 @@
p
In this example, we are using JXPath to access a property of the
codeemp/code bean.
- In this simple case the invocation of JXPath is equivalent to invocation of
getFirstName()
- on the bean.
+ In this simple case the invocation of JXPath is equivalent to invocation of
+ codegetFirstName()/code on the bean.
/p
/subsection
+subsection name=Lenient Mode
+p
+The codecontext.getValue(xpath)/code method throws an exception if the
+supplied xpath does not map to an existing property. This
+constraint can be relaxed by calling codecontext.setLenient(true)/code.
+In the lenient mode the method merely returns null if the path maps to nothing.
+/p
+/subsection
subsection name=Nested Bean Property Access
p
@@ -104,7 +116,7 @@
In this case XPath is used to access a property of a nested bean.
/p
p
- A property identified by the xpath does not have to be a leaf property.
+ A property identified by the XPath does not have to be a leaf property.
For instance, we can extract the whole Address object in above example:
/p
source
@@ -139,6 +151,30 @@
/p
/subsection
+subsection name=Retrieving Multiple Results
+ p
+ JXPath can retrieve multiple objects from a graph. Note that the method
+ called in this case is not codegetValue/code, but codeeval/code.
+ /p
+ source
+ #xA0;
+ public class Author {
+public Book[] getBooks(){
+ ...
+}
+ }
+
+ Author auth = new Author();
+ ...
+
+ JXPathContext context = JXPathContext.newContext(auth);
+ List threeBooks = (List)context.eval(books[position() lt; 4]);
+ /source
+ p
+ This returns a list of at most three books from the array of all books
+ written by the author.
+ /p
+/subsection
subsection name=Map Element Access
p
@@ -147,21 +183,19 @@
source
#xA0;
public class Employee {
-public Map getAddresses(){
- return addressMap;
+private Map addressMap = new HashMap();
+{
+addressMap.put(home, new Address(...));
+addressMap.put(office, new Address(...));
}
-public void addAddress(String key, Address address){
- addressMap.put(key, address);
+public Map getAddresses(){
+ return addressMap;
}
...
}
Employee emp = new Employee();
- emp.addAddress(home, new Address(...));
- emp.addAddress(office, new Address(...));
- ...
-
JXPathContext context = JXPathContext.newContext(emp);
String homeZipCode =
(String)context.getValue(addresses/home/zipCode);
@@ -177,11 +211,14