Is it possible to extract the node name using apache digester?
So, if the xml looks like
.....
This is the kind of matching that ExtendedBaseRules
afford.
Let's say this is the content of furniture.xml
:
Let's say you want to get the element names of the direct children of furniture
element. This is what furniture/?
matches in the ExtendedBaseRules
.
import java.io.*;
import java.util.*;
import org.apache.commons.digester.*;
public class FurnitureDigest {
public static void main(String[] args) throws Exception {
File file = new File("furniture.xml");
Digester digester = new Digester();
digester.setRules(new ExtendedBaseRules());
final List furnitures = new ArrayList();
digester.addRule("furniture/?", new Rule() {
@Override public void end(String nspace, String name) {
furnitures.add(name);
}
});
digester.parse(file);
System.out.println(furnitures); // prints "[sofa, coffeeTable]"
}
}