DOM4J
XML解析
1. 常用API
2. 解析XML获取文档对象
public static void main ( String [] args ) {// 创建SAXReader对象SAXReader reader = new SAXReader ();// 解析XML获取Document对象try {Document doc reader . read ( "/bin/LocalList.xml" );} catch DocumentException e {printStackTrace ();}}
3. 获取节点文本内容
private
static
String
getElementText
(
Document
doc
)
{
// 获取根节点
Element
root
=
.
getRootElement
();
// 获取指定节点集合
List
<
Element
>
elements
root
elements
(
"City"
);
// 获取指定节点
e
elements
get
(
7
);
text
e
getText
();
return
text
;
}