Java exception reading xml file
Posted
by xain
on Stack Overflow
See other posts from Stack Overflow
or by xain
Published on 2010-05-25T00:50:53Z
Indexed on
2010/05/25
1:01 UTC
Read the original article
Hit count: 356
Hi, I have the following xml file:
<?xml version="1.0" encoding="UTF-8"?>
<c1>
<c2 id="0001" n="CM" urlget="/at/CsM" urle="/E/login.jsp">
</c2>
<c2 id="0002" n="C2M" urlget="/a2t/CsM" urle="/E2/login.jsp">
</c2>
</c1>
I'm trying to load c2's attributes this way:
Document d =
DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse("epxy.xml");
Element c1 = d.getDocumentElement();
Element c2 = (Element)c1.getFirstChild();
while (c2 != null) {
...
c2 = (Element)c2.getNextSibling();
}
But I get the exception java.lang.ClassCastException: org.apache.xerces.dom.DeferredTextImpl incompatible with org.w3c.dom.Element in the line
Element c2 = (Element)c1.getFirstChild();
before the loop.
Any hints ? Thanks.
© Stack Overflow or respective owner