-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
57 lines (44 loc) · 1.51 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Declarative API for XML
===================================================
Ryan Cox
ryan.a.cox@gmail.com - http://www.asciiarmor.com
===================================================
Inspired by XSLTO, I’ve put together a bit of code to allow XSLT like tranformations from within Java. DAX glues together Java 5 annotations, Jaxen XPath and DOM4J to make possible the declarative style of processing shown below.
public class BindingTransform extends Transformer {
public List items = new ArrayList();
private RSSItem currentItem;
public BindingTransform() {
// tell engine about anticipated namespace
setNamespace("dc", "http://purl.org/dc/elements/1.1/");
}
public void init() {
items.clear();
}
public void complete() {
for (RSSItem i : items) {
System.out.println(i.getTitle());
}
}
@Path("//item")
public void item(Node node) {
currentItem = new RSSItem();
items.add(currentItem);
applyTemplates(node);
}
@Path("item/title")
public void title(Node node) {
currentItem.setTitle(node.getStringValue());
}
@Path("item/link")
public void link(Node node) {
currentItem.setLink(node.getStringValue());
}
@Path("item/description")
public void description(Node node) {
currentItem.setDescription(node.getStringValue());
}
@Path("item/dc:creator")
public void creator(Node node) {
currentItem.setCreator(node.getStringValue());
}
}