The method getTextContent() is undefined for the type Node
2015-07-13 11:38
661 查看
The method getTextContent() is undefined for
the type Node
eclipse 中 如果加入了 其他了xfire 等其他xml解析包的话,使用org.w3c.dom.Node下的getTextContent()方法会出现The method getTextContent() is undefined for the type Node 提示,解决方法如下:project-->properties->java build path-->order and export 把JRE System 提升到顶部既可,前提记得是java版本是jdk1.5以上
public static Map<String,Object> getMapFromXML(String xmlString) throws ParserConfigurationException, IOException, SAXException {
//这里用Dom的方式解析回包的最主要目的是防止API新增回包字段
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputStream is = Util.getStringStream(xmlString);
Document document = builder.parse(is);
//获取到document里面的全部结点
NodeList allNodes = document.getFirstChild().getChildNodes();
Node node;
Map<String, Object> map = new HashMap<String, Object>();
int i=0;
while (i < allNodes.getLength()) {
node = allNodes.item(i);
if(node instanceof Element){
map.put(node.getNodeName(),node.getTextContent());
}
i++;
}
return map;
}
相关文章推荐
- [INS-40901] The cluster node information table is unfilled 解决方案
- node.js(一)
- node.js安装
- node.js表单——formidable
- Node:链式前向星
- Node:原地归并
- node js 修改js代码自动发布到服务器
- node.js入门
- Populating Next Right Pointers in Each Node II
- nodejs学习之模块:crypto和body-parser
- node命令
- NodeJS学习第一季-阻塞与非阻塞
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- ubuntu14.04下安装node.js
- nodejs npm常用命令
- NodeJS学习第一季-HelloWorld
- NodeJS学习第一季-安装与介绍
- hadoop-2.6.0 Unhealthy Nodes 问题
- LeetCode 24: Swap Nodes in Pairs