NodeList n1 = dom.getChildNodes();
Element e1 = (Element) n1.item(0);
The node is not an Element
, but a Node
.
Try this:
Node no1 = (Node) n1.item(0);
Nodes can be text nodes or elements, for example. In particular,
<root>
<element/>
</root>
is 4 nodes. A root
element, a text node containing \n
, the element
element and another text node containing \n
.