栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何解析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;}

要清理它,但效果很好。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/516305.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号