0
我有一个xml文件,我试图使用stax xml解析器拍摄< _3-auto>节点中的文本。文本在任何节点内都不正确,所以stax无法取值。是否有其他方法可以使用stax来取值。从xml中获取元素文本,该文本在节点内部不正确
<_3-auto>
<prefix>
<autonum>(3)</autonum>
</prefix>
Remove the rear fuselage support from FS755.00 of the aircraft.
</_3-auto>
<_3-auto>
<prefix>
<autonum>(4)</autonum>
</prefix>
Put the hydraulic scissor lift (1) under the nose ballast assembly (2).
</_3-auto>
这是我编写的代码,以采取_3自动节点内的文本。
try {
XMLInputFactory inputFactory;
inputFactory = XMLInputFactory.newInstance();
InputStream inputStream = new FileInputStream(filePath);
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(inputStream);
while (streamReader.hasNext()) {
int event = streamReader.next();
if (event == XMLStreamConstants.START_ELEMENT) {
if (streamReader.getLocalName().equals("_3-auto")) {
String auto = streamReader.getElementText();
System.out.println(auto);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}