项目报错:The method getTextContent() is undefined for the type Node

本文描述了一个关于XML解析的问题:当项目中同时使用了多种XML解析包时,尝试调用org.w3c.dom.Node下的getTextContent()方法会遇到未定义错误。文章提供了简单有效的解决方案:通过调整项目的JRE系统库顺序来解决此问题。

一、问题描述

 

在项目中使用了XML解析,如果加入了其他了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 提升到顶部既可

void XMLProcessor::generateDriver(DOMNode *pNode) { DOMNode *t_node = pNode->getFirstChild(); while (t_node != NULL) { //if the node is element node, then do... if (isElementNode(t_node)) { string attrType = getNodeAttribute(t_node, "type"); if (strcasecmp(attrType.c_str(), "instance") == 0) { string claName = getNodeAttribute(t_node, "class"); const ClassJoint *t_joint = ManagedObject::load(claName); if (t_joint == NULL) { throw XMLParseException("Build drivers failed! There is no such joint named \"" + claName + "\" in class-joint list."); } // create object by the classjoint related to the class ManagedObject *t_obj = NULL; try { t_obj = t_joint->createObject(); // user may throw exception here } catch (const exception &err) { throw XMLParseException("Build drivers failed! Cannot create object at the node \"" + getNodeFullName(t_node) + "\". " + string(err.what())); } catch (const string &err) { throw XMLParseException("Build drivers failed! Cannot create object at the node \"" + getNodeFullName(t_node) + "\". " + err); } catch (const char *err) { throw XMLParseException("Build drivers failed! Cannot create object at the node \"" + getNodeFullName(t_node) + "\". " + string(err)); } catch (...) { throw XMLParseException("Build drivers failed! Cannot create object at the node \"" + getNodeFullName(t_node) + "\". "); } string simulated = getNodeAttribute(t_node, "simulated"); // check if the sub-method node contains "setSimulated" // for (DOMNode *node = t_node->getFirstChild(); node != NULL; node = node->getNextSibling()) { if (isElementNode(node)) { XStr nodeName(node->getNodeName()); XStr content(node->getTextContent()); if (strcmp(nodeName.self(), "setSimulated")==0 && simulated=="") { simulated = string(content.self()); } } } if (!simulated.empty()) // is NOT default (false) { if (simulated == "true") { t_obj->setSimulated(true); } else if ((simulated != "false") && (simulated != "")) { delete t_obj; // destroy t_obj throw XMLParseException("Build drivers failed! Invalid simulated flag at the node \"" + getNodeFullName(t_node) + "\". "); } } // parse the method-node and config for (DOMNode *node=t_node->getFirstChild(); node!=NULL; node=node->getNextSibling()) { XStr nodeName(node->getNodeName()); XStr content(node->getTextContent()); string attrMType = getNodeAttribute(node, "type"); // skip the no-method node if ((attrMType=="") || (strcasecmp(attrMType.c_str(), "method")!=0)) continue; try { ((CmdTarget*)t_obj)->dispatchMsg(nodeName.self(), content.self()); // throw DispatchMsgFailedException } catch (const exception &err) { // Cannot delete t_obj without error, because the t_obj may be registered in DeviceManager // through init() method already. <><><> If the t_obj has NOT been registered, its resource // will be release by the Process. TODO: Delete t_obj properly! // throw XMLParseException("Build drivers failed! Configuration error occurred at the node \"" + getNodeFullName(node) + "\". " + string(err.what())); } } } } else { generateDriver(t_node); } t_node = t_node->getNextSibling(); } } 逐行解释代码
最新发布
08-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值