解析XML碰到的问题,请帮忙指教,谢谢
ATGC 2005-12-13 04:58:22 test1.xml
<?xml version="1.0" encoding="utf-8"?>
<entrySet xmlns="net:sf:psidev:mi"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="net:sf:psidev:mi http://psidev.sourceforge.net/mi/xml/src/MIF.xsd"
level="1" version="1">
<author name="James" location="UK">James Strachan</author>
<author name="Bob" location="US">Bob McWhirter</author>
</entrySet>
test2.xml
<?xml version="1.0" encoding="utf-8"?>
<entrySet>
<author name="James" location="UK">James Strachan</author>
<author name="Bob" location="US">Bob McWhirter</author>
</entrySet>
代码1
File f = new File("test1.xml");
SAXReader reader = new SAXReader();
Document doc = reader.read(f);
Element root = doc.getRootElement();
Node node = doc.selectSingleNode("/entrySet/author");
String id = node.valueOf("@id");
System.out.println(id);
代码2
File f = new File("test2.xml");
SAXReader reader = new SAXReader();
Document doc = reader.read(f);
Element root = doc.getRootElement();
Node node = doc.selectSingleNode("/entrySet/author");
String id = node.valueOf("@id");
System.out.println(id);
我的XML文件test1.xml的root节点entrySet后面的内容如果去掉test2.xml,我的程序就可以
如果和test1.xml那样,我就取不到author的id,
不知道为什么?帮忙指教,谢谢。。