用Java解析高级XML

用Java解析高级XML,第1张

用Java解析高级XML

//规范化您的XML,然后

document
通过该XML 创建一个,然后遵循以下代码

NodeList nList = doc.getElementsByTagName("foo");        for (int temp = 0; temp < nList.getLength(); temp++) { // loop for foo Node nodeTable = nList.item(temp); Element xmlFoo = (Element) nodeTable; if (nodeTable.getNodeType() == Node.ELEMENT_NODE) { NodeList nodeListFoo1 = xmlFoo.getElementsByTagName("foo1"); for (int i = 0; i < nodeListFoo1.getLength(); i++) { // loop for foo1     Node nodefoo2 = nodeListFoo1.item(i);     Element elementfoo1 = (Element) nodefoo2;     // Collect foo2      NodeList nodeListfoo2Name = elementfoo1.getElementsByTagName("foo2");     for (int j = 0; j < nodeListfoo2Name.getLength(); j++) { //// loop for foo2         Node nodefoo2Name = nodeListfoo2Name.item(j);         Element elementfoo2Name = (Element) nodefoo2Name;         //TODO: write pre here, what you want to collect from foo2         }     } }        }


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

原文地址: http://outofmemory.cn/zaji/5500410.html

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

发表评论

登录后才能评论

评论列表(0条)

保存