package br.com.teste;
import java.io.IOException;
import javax.lang.model.element.Element;
import javax.swing.text.Document;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class Sistema {
public static void main(String[] args) throws Exception {
DocumentBuilderFactory fabrica = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = fabrica.newDocumentBuilder();
Document document = (Document) builder.parse("src/vendas.xml");
NodeList formasDePagamento = ((org.w3c.dom.Document) document).getElementsByTagName("formaDePagamento");
Element fdp= (Element) formasDePagamento.item(0);
String formaDePagamento = ((Node) fdp).getTextContent();
System.out.println(formaDePagamento);
}
}
Exception in thread "main" java.lang.ClassCastException: class com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl cannot be cast to class javax.swing.text.Document (com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl is in module java.xml of loader 'bootstrap'; javax.swing.text.Document is in module java.desktop of loader 'bootstrap')
at br.com.teste.Sistema.main(Sistema.java:24)