我正在读取与以下相同的 XML 文件:
<ts>
<tr comment="" label="tr1">
<node order="1" label="" />
</tr>
</ts>
我预计下面的代码会e
在屏幕上打印出三个:
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader sr = factory.createXMLStreamReader(new FileReader("test.xml"));
while (sr.hasNext()) {
int eventType = sr.next();
if (eventType == XMLStreamReader.START_DOCUMENT) {
continue;
} else if (eventType == XMLStreamReader.END_ELEMENT) {
System.out.println("e");
} else if (eventType == XMLStreamReader.START_ELEMENT) {
System.out.println("s");
}
}
但它不起作用!关于如何解决问题的任何想法?
注意:我认为它与自封闭标签有关,例如:<myTag id="1" />