Get set reference Beanutil package and Xpath
http://commons.apache.org/'s Jxpath User ' s Guide
Loading of classes
JXPathContext context=JXPathContext.newContext( obj );
//和 xpath 的 范围确定
General value stored value
String fName=(String)context.getValue("firstName"); //setValue
//参考 http://www.blogjava.net/Good-Game/archive/2007/08/10/135739.html
General statistics and use of C for list [Id,name,.....]
Jxpathcontext context = Jxpathcontext.newcontext (c);
System.out.println (Context.getvalue ("count (. [ Name= ' oo ' and id= ' 1 ')); The number of objects Name=oo and id=1
System.out.println (Context.getvalue ("Sum" (). [ Name= ' oo ' and id= ' 1 ']/id))//Object Name=oo and id=1 all IDs are added
Get Set
Iterator threeBooks=context.iterate("books[position()<4]");
//xpath 的位置函数 position 其他函数参考 http://www.w3.org/TR/xpath
//4 Core Function Library
XPath uses
public class Employee {
Private Map Addressmap = new HashMap ();
{ addressmap.put ("Home", new address (...));
Addressmap.put ("Office", new Address (...));
}
Public Map getaddresses () {
return addressmap;
}
...
}
String homezipcode = (string) context. GetValue ("addresses[@name = ' home ']/zipcode");
Using the Addressmap Map key = home Address class attribute ZipCode
The entry point of XML in program and XPath
<?xml version= "1.0"?>
<vendor>
<location id= "store101" >
<address>
<street>orchard road</street>
</address>
</location>
<location id= "store102" >
<address>
<street >tangerine drive</street>
</address>
</location>
</vendor>
Class Company {
private Container locations = null;
Public Container getlocations () {
if (locations = null) {
URL url = getclass (). GetResource ("Vendor.xml");
locations = new Xmldocumentcontainer (URL);
}
return locations;
}
}
...
Context = Jxpathcontext.newcontext (new company ());
...
String street = (string) context.getvalue (
"locations/vendor/location[@id = ' store102 ']//street");
Class Container Properties Locations header vendor (in XML) ...