感谢Marcin Krol,我找到了一个例子并得到了它:
static List<String> parseScenarioByGist() { Map<String, List<String>> map = new linkedHashMap<String, List<String>>(); String path = "/Users/haddad/development/industry/generalatomics/v1/gists_xml/Absolutevalue.xml"; try { document doc = getdocument(path); XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); XPathexpression expr = xpath.compile("/*/Scenarios/Scenario/ID"); NodeList nList = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); Integer count = 1; List<String> list = new ArrayList<String>(); for(int i=0;i<nList.getLength();i++) { Node n = nList.item(i); System.out.println("Node Name: "+n.getTextContent()); list.add(n.getNodeName()); count++; } return list; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (XPathexpressionException e) { e.printStackTrace(); } return null;}
要清理它,但效果很好。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)