为什么我的运行结果是这样的?

package com.imooc.Dom4jTest;

import java.io.File;
import java.util.Iterator;
import java.util.List;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class DOM4JTest {
	public static void main(String[] args) {
		SAXReader reader = new SAXReader();
		try {
			Document document = reader.read(new File("src/res/books.xml"));
			Element bookStore = document.getRootElement();
			Iterator it = bookStore.elementIterator();
			while (it.hasNext()) { 
				System.out.println("------------开始遍历某本书---------------");
				Element book = (Element) it.next();
				List<Attribute> bookAttrs = book.attributes();
				for (Attribute attr : bookAttrs) {
					System.out.println("属性名:" + attr.getName() + "------属性值"
							+ attr.getValue());
				}
				Iterator itt = book.elementIterator();
				while (itt.hasNext()) {
					Element bookChild = (Element) itt.next();
						System.out.println("节点名:" + bookChild.getName()
							+ "----节点值:" +bookChild.getStringValue());
					}
				System.out.println("------------结束遍历某本书---------------");
			}
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

http://img.mukewang.com/594f7f0400015ba103910406.jpg

lambLHB
浏览 1099回答 1
1回答

HOTLINE

循环套错了?
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java