如何解析XML以检索嵌入式文本节点

如何解析XML以检索嵌入式文本节点,第1张

如何解析XML以检索嵌入式文本节点

感谢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;}

清理它,但效果很好。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5507445.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-13
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存