`

com.sun.org.apache.xerces.internal.dom.DeferredTextImpl cannot be cast to org.w3

xml 
阅读更多
public class DomXmlTest{
    public static void main(String[] args) {
		DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
		try {
			DocumentBuilder db=dbf.newDocumentBuilder();
			Document doc=db.parse("test/url.xml");
			NodeList ol=doc.getElementsByTagName("helloworld");
			for(int i=0;i<ol.getLength();i++){
				Element e=(Element) ol.item(i);
				System.out.println(e.getAttribute("name"));
				NodeList ol1=e.getChildNodes();
				for(int k=0;k<ol1.getLength();k++){
                    //在xml文档节点前存在回车,制表符等都会占用一个节点Node,这一类Node是无法转为Element,会抛com.sun.org.apache.xerces.internal.dom.DeferredTextImpl cannot be cast to org.w3c.dom.Element。可在前加if判断节点类型
                        if(ol1.item(k).getNodeType()==Node.ELEMENT_NODE){
				Element e1=(Element) ol1.item(k);
				System.out.println(e1.getNodeName());
                            }
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
分享到:
评论

相关推荐

    org.apache.xerces-2.9.0.jar/xerces.jar

    例如,如果你的项目使用了需要Xerces支持的库,或者你自己编写了依赖于Xerces的代码,那么你需要确保将"org.apache.xerces-2.9.0.jar"或"xerces.jar"添加到项目的类路径中。你可以通过Maven、Gradle等构建工具进行...

    com.springsource.org.apache.xerces-sources-2.8.1.jar

    jar包,官方版本,自测可用

    java.lang.AbstractMethodError: org.apache.xerces.dom.DocumentImpl.setXmlVersion问题解决方法

    在这个特定的情况下,错误提示`org.apache.xerces.dom.DocumentImpl.setXmlVersion`指出问题源于Apache Xerces的DOM实现,它是一个流行的XML解析库。 `AbstractMethodError`通常意味着缺少了某个依赖或版本冲突。...

    xerces-2.9.0.jar

    Xerces是由Apache软件基金会开发的,它是遵循Apache Software License 2.0(见xerces_license.txt文件)的开放源代码项目。这个强大的解析器支持XML 1.0和1.1规范,以及相关的XML Schema、XPath、XSLT和DOM等标准。...

    apache-xml-xerces.jar.zip

    - **配置解析器**:在Java代码中,可以通过`org.apache.xerces.jaxp.DocumentBuilderFactoryImpl`或`org.apache.xerces.jaxp.SAXParserFactoryImpl`来创建并配置解析器。 - **错误处理**:解析过程中如果遇到错误,...

    spring-framework-3.0.5.RELEASE-dependencies-1

    org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache.struts org.apache.taglibs 5号包: org.codehaus.castor org.aspectj org.beanshell 6...

    spring-framework-3.0.5.RELEASE-dependencies-5

    org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache.struts org.apache.taglibs 5号包: org.codehaus.castor org.aspectj org.beanshell 6...

    spring-framework-3.0.5.RELEASE-dependencies-6

    org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache.struts org.apache.taglibs 5号包: org.codehaus.castor org.aspectj org.beanshell 6...

    spring-framework-3.0.5.RELEASE-dependencies-3

    org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache.struts org.apache.taglibs 5号包: org.codehaus.castor org.aspectj org.beanshell 6...

    svg2vector-cli-1.0.1.jar

    将SVG(矢量图)批量转换为vector的工具库。 (java -jar svg2vector-cli-1.0.1.jar -d . -o svg) (-d:批量转换的源文件地址 -f:单个转换的源文件地址 -o:转换后要输出的文件地址 ...-w:输出的宽)

    spring-framework-3.0.5.RELEASE-dependencies-2

    org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache.struts org.apache.taglibs 5号包: org.codehaus.castor org.aspectj org.beanshell 6...

    spring-framework-3.0.5.RELEASE-dependencies-8

    org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache.struts org.apache.taglibs 5号包: org.codehaus.castor org.aspectj org.beanshell 6...

    spring-framework-3.0.5.RELEASE-dependencies-4

    org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache.struts org.apache.taglibs 5号包: org.codehaus.castor org.aspectj org.beanshell 6...

    spring-framework-3.0.5.RELEASE-dependencies-7

    org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache.struts org.apache.taglibs 5号包: org.codehaus.castor org.aspectj org.beanshell 6...

    com.springsource.org.apache.xerces-2.9.1.jar

    jar包,官方版本,自测可用

    Xerces-J-src.2.10.0

    Xerces Java包: org.apache.xerces.dom——Xerces DOM实现 org.apache.xerces.parsers——Xerces解析器;DOM和SAX org.apache.xerces.serialize——将DOM树序列化到文件、输出流和编写器

    [免费]xercesImpl-2_9_1.jar-CSDN下载

    java.lang.AbstractMethodError: org.apache.xerces.dom.ElementNSImpl.setUserData(Ljava/lang/String;Ljava/lang/Object;Lorg/w3c/dom/UserDataHandler;)Ljava/lang/Object; at org.apache.cxf.staxutils.StaxUtil...

    xerces.jar.zip

    《Apache SOAP与Tomcat中的Web服务实现:xerces.jar深度解析》 在现代Web开发领域,Web服务已经成为跨系统通信的重要方式。Apache SOAP(Simple Object Access Protocol)是开源项目,提供了一种基于XML的协议,...

    javaHighcharts 导出图表的batik 等资源包

    import org.apache.batik.transcoder.Transcoder; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder....

Global site tag (gtag.js) - Google Analytics