xml文件:
<span style="font-size:14px;"><?xml version="1.0" encoding="UTF-8"?>
<interface_group id="jiangxiliantong">
<jiangxiliantong_10>
<pruduct_10>225827</pruduct_10>
<pruduct_10>225825</pruduct_10>
<pruduct_10>225824</pruduct_10>
<pruduct_10>225823</pruduct_10>
<pruduct_10>225821</pruduct_10>
<pruduct_10>225820</pruduct_10>
<pruduct_10>225818</pruduct_10>
<pruduct_10>225816</pruduct_10>
<pruduct_10>225814</pruduct_10>
<pruduct_10>225810"</pruduct_10>
</jiangxiliantong_10>
<jiangxiliantong_30>
<pruduct_30>225839</pruduct_30>
<pruduct_30>225841</pruduct_30>
</jiangxiliantong_30>
</interface_group>
</span>
读取xml文件获取数据:
<span style="font-size:14px;">private List<String> getProductArr(String productname){
List<String> resultList = new ArrayList<>();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
//读取配置文件xml
String file ="jxltProduct-config.xml";
String fullFile = PathKit.getRootClassPath() + File.separator + file;
System.out.println(fullFile);
org.w3c.dom.Document doc = db.parse(fullFile);
//根据接口名称获取到接口配置
NodeList businessList = doc.getElementsByTagName(productname);
for(int i=0;i<businessList.getLength();i++){
Node business = businessList.item(i);
String parserName = business.getNodeName();
String parserValue = business.getFirstChild().getTextContent();
System.out.println(parserName + ":" + parserValue);
resultList.add(parserValue);
}
} catch (Exception e) {
e.printStackTrace();
}
return resultList;
}</span>