DOM4j
public static Map<String, String[]> getKeyValueFromXml(String xmlContent, String listPath, String keyName,
String... valName) {
Map<String, String[]> ret = new HashMap<String, String[]>();
org.dom4j.Document document = null;
try {
document = DocumentHelper.parseText(xmlContent);
} catch (DocumentException documentException) {
documentException.printStackTrace();
}
if (document != null) {
List<org.dom4j.Node> keyNodes = document.selectNodes(listPath);
for (org.dom4j.Node keyNode : keyNodes) {
if (keyNode instanceof Element) {
Element ele = (Element) keyNode;
String key = ele.elementText(keyName);
String[] val = new String[valName.length];
for (int i = 0; i < valName.length; i++) {
String val1 = ele.elementText(valName[i]);
val[i] = val1;
}
ret.put(key, val);
}
}
}
return ret;
}
追问用dom4j解析XML我知道 我是想问如何获取获取指定id下某一项的参数值 java语句该如何写
本回答被提问者采纳