我的代码有问题我假设我缺少一个方法,我想创建一个字符串列表,然后打印出内容。现在我已经编写了一些代码来为一个字符串执行此操作,但我想为多个字符串执行此操作。
@Test
public void xmlFileParse () throws ParserConfigurationException, IOException, SAXException {
List<String> fXmlFile = new ArrayList<String>();
fXmlFile.add("src/test/resources/fixtures/event.xml");
fXmlFile.add("src/test/resources/fixtures/country.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
NodeList nodes = doc.getElementsByTagName("subscription-update").item(0).getChildNodes();
for(int i = 0; i < nodes.getLength(); i++){
Node node = nodes.item(i);
if(node.getNodeType() == ELEMENT_NODE){
System.out.println("TABLE: [" + node.getNodeName() + "] ID: [" + node.getAttributes().getNamedItem("id").getNodeValue() + "]");
}
}
}
这是我目前收到的错误。
Error:(65, 32) java: no suitable method found for parse(java.util.List<java.lang.String>)
method javax.xml.parsers.DocumentBuilder.parse(java.io.InputStream) is not applicable
(argument mismatch; java.util.List<java.lang.String> cannot be converted to java.io.InputStream)
method javax.xml.parsers.DocumentBuilder.parse(java.lang.String) is not applicable
(argument mismatch; java.util.List<java.lang.String> cannot be converted to java.lang.String)
method javax.xml.parsers.DocumentBuilder.parse(java.io.File) is not applicable
(argument mismatch; java.util.List<java.lang.String> cannot be converted to java.io.File)
method javax.xml.parsers.DocumentBuilder.parse(org.xml.sax.InputSource) is not applicable
(argument mismatch; java.util.List<java.lang.String> cannot be converted to org.xml.sax.InputSource)