iFile = getEditor().getEditorInput().getAdapter(IFile.class);
File file = new File(iFile.getLocation().toString());
Map<String, String> columnsMap = new HashMap<>();
if (file.exists()) {
SAXReader reader = new SAXReader();
try {
document = reader.read(file);
Element root = document.getRootElement().element("Bmt");
Attribute mAttribute = root.attribute("localLabel");
type = root.attribute("type").getValue();
TypeName = root.attribute("typename").getValue();
if (mAttribute == null) {
localLabel = "";
} else {
localLabel = mAttribute.getValue();
}
Element rows = root.element("rows");
if (rows != null) {
List<Element> linksElements = rows.elements("links");
for (Element element : linksElements) {
switch(element.attributeValue("name")) {
case "authorName":
text_6.setText(getValue(element));
break;
case "edition":
text_7.setText(getValue(element));
break;
case "operationalArea":
text_8.setText(getValue(element));
break;
case "battlefieldEnvironment":
text_9.setText(getValue(element));
break;
case "startTime":
Date sdate = parseDateString(getValue(element));
if (sdate != null) {
dateTime.setDate(sdate.getYear() + 1900, sdate.getMonth(), sdate.getDate());
}
break;
case "endTime":
Date edate = parseDateString(getValue(element));
if (edate != null) {
dateTime_1.setDate(edate.getYear() + 1900, edate.getMonth(), edate.getDate());
}
break;
case "threatTarget":
text_10.setText(getValue(element));
break;
case "operationalBackground":
text_11.setText(getValue(element));
break;
case "backgroundLink"://背景链接
List<Element> backgroundElements = element.elements("link");
backgroundLink.clear();
for (Element bgElement : backgroundElements) {
TableItem newItem = new TableItem(table_1, SWT.NONE);
newItem.setText(bgElement.getText());
backgroundLink.put(bgElement.getText(), "");
}
createTableFile();
break;
case "missions"://使命任务
List<Element> missionsElements = element.elements("link");
missMap.clear();
for (Element misElement : missionsElements) {
Map<String, String> mission = new HashMap<>();//使命任务
TableItem newItem = new TableItem(table_2, SWT.NONE);
newItem.setText(0,misElement.attributeValue("name"));
newItem.setText(1,misElement.getText());
newItem.setData(misElement.attributeValue("id"));
mission.put(misElement.attributeValue("name"), misElement.getText());
missMap.put(misElement.attributeValue("id"), mission);
}
createTableFile();
break;
}
}
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
标签:Xml,case,java,setText,getValue,break,misElement,element,解析
From: https://blog.51cto.com/u_16340211/8843673