我使用XStream库解析一些xml文件。结果是每个文件的映射。当我调试时,结果图是我正在寻找的,但是当我转到下一行时,地图的值会突然变化!但是它不会在“for”循环中进行下一轮,它包含下一个文件的信息。是什么导致它?
public class Debug {
public String path = "E:\\Projects\\svn\\FANRPProduction\\WMS\\src\\main\\resources\\wms\\bpmn\\bp";
public XStream xStream;
public Map<String, List<CallActivity>> bpTpMap;
public void findBPandTP() throws IOException {
File root = new File(path);
File[] xmlFiles = FindAllXMLFiles.recursive(root);
bpTpMap=new HashMap<String, List<CallActivity>>();
for (File xml : xmlFiles) {
if (xml != null) {
xStream = new XStream(new StaxDriver());
xStream.alias("definitions", CallActivity.class);
xStream.registerConverter(new CallActivityConverter());
bpTpMap = (Map) xStream.fromXML(xml);//Here I get correct information. For example "WMS_RBP_OutgoingWeighing"
List<String> bpList = new ArrayList<String>(bpTpMap.keySet()); //Here I see the name of the next file in the path in bpTpMap, which is "WMS_BP_WeighingConfiguration"
}
}
}
}
答案 0 :(得分:0)
我建议您使用以下内容进行调试:
bpTpMap = (Map) xStream.fromXML(xml);//Here I get correct information. For example "WMS_RBP_OutgoingWeighing"
System.out.println(bpTpMap.size());
Set<String> setOfKeys = bpTpMap.keySet();
System.out.println("Initial value of keys:"+bpTpMap);//Here you would see any extra values if the map has it