jjzjj

DeferredTextImpl

全部标签

java - 错误 : org. apache.xerces.dom.DeferredTextImpl 无法转换为 org.w3c.dom.Element

XML:A我正在尝试获取“id”值。但不断收到此错误:org.apache.xerces.dom.DeferredTextImplcannotbecasttoorg.w3c.dom.Element我的代码:for(inti=0;i如果我写:System.out.println("parentnodeis"+n.getParentNode());在给我的for循环中,[detail:null]任何帮助将不胜感激。 最佳答案 在将节点转换为元素之前,您需要检查节点是否为元素。这是将Node转换为Element的方法:NodeListno

Java XML : ClassCastException DeferredTextImpl

这是我的代码://getthefactoryDocumentBuilderFactorydbf=DocumentBuilderFactory.newInstance();try{//UsingfactorygetaninstanceofdocumentbuilderDocumentBuilderdb=dbf.newDocumentBuilder();//parseusingbuildertogetDOMrepresentationoftheXMLfiledom=db.parse(file);}catch(ParserConfigurationExceptionpce){pce.prin