Galera do Portal,
Estou tentando usar o JDOM para mudar os dados do meu XML. So que esta dando java.lang.ClassCastException.
Segue o meu XML e o codigo que estou rodando.
Primeiro Codigo XML
<?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns:journal="http://www.w3.org/2001/XMLSchema-Instance" >
<journal:journal title="XML" publisher="IBM developerWorks">
<article journal:level="Intermediate"
date="February-2003">
<title>Design XML Schemas Using UML</title>
<author>Ayesha Malik</author>
</article>
</journal:journal>
<journal title="Java Technology" publisher="IBM
developerWorks">
<article level="Advanced" date="January-2004">
<title>Design service-oriented architecture
frameworks with J2EE technology</title>
<author>Naveen Balani</author>
</article>
<article level="Advanced" date="October-2003">
<title>Advance DAO Programming</title>
<author>Sean Sullivan </author>
</article>
</journal>
<vcs teste="vcs">
vcs
</vcs>
</catalog>
Agora segue o meu codigo java
import java.io.File;
import org.jdom.input.SAXBuilder;
import org.jdom.xpath.XPath;
public void lerXml(){
try {
Object o = null;
File xmlDocument = new File("D:\\temp\\TesteLog4J\\src\\teste.xml");
SAXBuilder saxBuilder = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
org.jdom.Document jdomDocument = saxBuilder.build(xmlDocument);
org.jdom.Attribute levelNode = (org.jdom.Attribute)(XPath.selectSingleNode(jdomDocument,"/catalog//vcs[@teste='vcs']"));
levelNode.setValue("Intermediate");
} catch (Exception e) {
e.printStackTrace();
}
}
Agora quando eu uso essa linha
org.jdom.Attribute levelNode = (org.jdom.Attribute)(XPath.selectSingleNode(jdomDocument,"/catalog//journal[@title='JavaTechnology']" + "//article[@date='January-2004']/@level"));
O erro que da é java.lang.NullPointerException
Valeu mais uma vez galera!!!