为了账号安全,请及时绑定邮箱和手机立即绑定

这怎么解决

这怎么解决

qq_果汁分ni半_03462240 2016-12-30 23:42:03
package com.imooc.domtest.test;import java.io.IOException;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.ParserConfigurationException;import org.w3c.dom.Document;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.xml.sax.SAXException;public class DomTest {  public static void main(String[] args) {      DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();  try{  DocumentBuilder db=dbf.newDocumentBuilder();  Document document=db.parse("books.xml");  NodeList bookList=document.getElementsByTagName("book");  System.out.println("一共有"+bookList.getLength()+"书本");    for(int i=0;i<bookList.getLength();i++){   System.out.println("====下面开始遍历第"+(i+1)+"本书内容====");   Node book=bookList.item(i);   NamedNodeMap attrs=book.getAttributes();   System.out.println("第"+(i+1)+"本书共有"+attrs.getLength()+"个属性");      for(int j=0;j<attrs.getLength();j++){    Node attr=attrs.item(j);    System.out.print("属性名:"+attr.getNodeName());    System.out.println("---属性值"+attr.getNodeValue());   }   System.out.println("====下面结束遍历第"+(i+1)+"本书内容====");  }  }catch(ParserConfigurationException e){   e.printStackTrace();  }catch(SAXException e){   e.printStackTrace();  }catch(IOException e){   e.printStackTrace();  } }}错误提示:[Fatal Error] books.xml:13:37: The element type "language" must be terminated by the matching end-tag "</language>".org.xml.sax.SAXParseException: The element type "language" must be terminated by the matching end-tag "</language>". at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:239) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283) at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:180) at com.imooc.domtest.test.DomTest.main(DomTest.java:24)
查看完整描述

1 回答

已采纳
?
biohazard4

TA贡献12条经验 获得超2个赞

  你检查一下books.xml的结构有没有错误,他报的错是说language标签没有缺少了对应的结束标签"</language>"

查看完整回答
反对 回复 2016-12-31
  • 1 回答
  • 0 关注
  • 1911 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信