java中dom方式读取xml,怎样根据xml的某个属性找到指定节点?? 比如id属性

如题所述

Element rootEle = dom.getRootElement();
rootEle.getAttributeValue("id") 还是rootEle.getChild(name)?

最好有个XML例子 不清楚说的指定节点是啥意思
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-06-14
用dom4j
xpath
http://www.zvon.org/xxl/XPathTutorial/General/examples.html追问

还是不大明白,能说具体点吗?最好有代码

追答

上面
导入dom4j所需的jar包
SAXReader reader = new SAXReader();
Document document = reader.read(new File(path));
Element e = (Element) document.selectSingleNode("xpath");
xpath的就看教程了。

第2个回答  2012-06-14
看了你写的代码。是用sax解析xml啊,不用导入dom4j
相似回答