您的位置:首页 > Web前端 > Node.js

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: