求高手帮忙JAVA 读取XML 文件,下面是我的XML文件,怎么在JAVA中 把他们全部显示出来。
<?xmlversion="1.0"encoding="utf-8"?><bookconfig><name>22</name><package>AOTCOCNVKUPQX...
<?xml version="1.0" encoding="utf-8"?>
<bookconfig>
<name>22</name>
<package>AOTCOCNVKUPQXUDP</package>
<author>22</author>
<category>Novels</category>
<description>1</description>
<lowicon></lowicon>
<middleicon></middleicon>
<highicon></highicon>
<cover></cover>
<fontsize>15</fontsize>
<stayscreen>1</stayscreen>
<linespace>2</linespace>
<dayfontcolor>0</dayfontcolor>
<daybackground>12310495</daybackground>
<nightfontcolor>16777215</nightfontcolor>
<nightbackground>0</nightbackground>
<versioncode>2</versioncode>
<versionname>1.0</versionname>
</bookconfig> 展开
<bookconfig>
<name>22</name>
<package>AOTCOCNVKUPQXUDP</package>
<author>22</author>
<category>Novels</category>
<description>1</description>
<lowicon></lowicon>
<middleicon></middleicon>
<highicon></highicon>
<cover></cover>
<fontsize>15</fontsize>
<stayscreen>1</stayscreen>
<linespace>2</linespace>
<dayfontcolor>0</dayfontcolor>
<daybackground>12310495</daybackground>
<nightfontcolor>16777215</nightfontcolor>
<nightbackground>0</nightbackground>
<versioncode>2</versioncode>
<versionname>1.0</versionname>
</bookconfig> 展开
展开全部
以下是我的答案,希望对你有帮助。
SAXReader xmlReader = new SAXReader();
try {
Document doc = xmlReader.read(new File("F:\\bookconfig.xml")); //读取xml配置文件
Element root = doc.getRootElement(); //获取根节点
List<Element> elements = root.elements(); //获取根节点下的所有子节点
for(Element element : elements){ //遍历子节点
System.out.println("节点名:"+element.getName()+",节点内文本:"+element.getData());
}
} catch (DocumentException e) {
e.printStackTrace();
}
SAXReader xmlReader = new SAXReader();
try {
Document doc = xmlReader.read(new File("F:\\bookconfig.xml")); //读取xml配置文件
Element root = doc.getRootElement(); //获取根节点
List<Element> elements = root.elements(); //获取根节点下的所有子节点
for(Element element : elements){ //遍历子节点
System.out.println("节点名:"+element.getName()+",节点内文本:"+element.getData());
}
} catch (DocumentException e) {
e.printStackTrace();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询