http://www.badboy.net.cn
badboy
2007
1
2
thinking in java2http://www.badboy.net.cn2
badboy2
20072
12
22
thinking in java3http://www.badboy.net.cn3
badboy3
20073
13
23
存于e:\
java:
先导入javax.xml.parser.*和org.w3c.dom.*
然后将文件解析为DOM对象:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse("e:/xml.xml");
doc.normalize(); // doc.nomalizeDocument();
取得标记内容和属性值:
NodeList books = doc.getElementsByTagName("book");
for(int i=0;i
{
Element book = (Element)books.item(i);
Element url = (Element)book.getElementsByTagName("url").item(0);
out.print(url.getAttribute("newWindow")+"
");
}
分享到:
2009-03-20 12:13
浏览 2551
评论