List getChildren(); // return all children
List getChildren(String name); // return all children by name
Element getChild(String name); // return first child by name
示例:
// Get a List of all direct children as Element objects
List allChildren = element.getChildren();
out.println("First kid: " + ((Element)allChildren.get(0)).getName());
// Get a list of all direct children with a given name
List namedChildren = element.getChildren("name");
// Get a list of the first kid with a given name
Element kid = element.getChild("name");
List mixedContent = table.getMixedContent();
Iterator i = mixedContent.iterator();
while (i.hasNext()) {
Object o = i.next();
if (o instanceof Comment) {
// Comment has a toString()
out.println("Comment: " + o);
}
else if (o instanceof String) {
out.println("String: " + o);
}
else if (o instanceof ProcessingInstruction) {
out.println("PI: " + ((ProcessingInstriction)o).getTarget());
}
else if (o instanceof Element) {
out.println("Element: " + ((Element)o).getName());
}
}
Jdom可以和已有的XML技术如Simple API for XML (SAX)和 Document Object Model (DOM)相互协作.然而,它并不是简单的从这些api中提取出一些。Jdom从这些已存在的技术中吸收了好的方面,自己建立了一套新的类和接口,用一个Jdom用户的话来说就是:“这些接口是我从一开始阅读org.w3c.dom就期待的”;Jdom可以读入SAX或是DOM的内容,也可以输出SAX或DOM可以接收的格式。这个能力可以使Jdom很好的和已有的用SAX或DOM建立的系统之间整合。