I have an error on the line
Document doc = builder.parse(is);// doc = null;
Where at the moment of using the builder.parse it becomes null which makes the error arise and is captured by the catch (Exception ex) saying that the doc is null, I am working with nice soft (version 7.3) and I am tried to consume a web service but when working with the xml does not allow me to advance more because of the error, thanks
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import java.lang.Exception;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
String ejemplo ="";
String ejemplo ="hola mundo ";
String aux1 ;
int n ;
boolean encontrado = false ;// bandera
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// use the factory to create a documentbuilder
DocumentBuilder builder = factory.newDocumentBuilder();
// create a new document from input source
InputSource is = new InputSource(new StringReader("weatherDataAsXML"));
try {
Document doc = builder.parse(is);// doc = null;
// get the first element
Element element = doc.getDocumentElement();
// get all child nodes
NodeList nodes = element.getChildNodes();
// print the text content of each child
for (int i = 0; i < nodes.getLength(); i++) {
//
ejemplo = ejemplo +""+ nodes.item(i).getTextContent();
}
} catch (Exception ex) {
StackTraceElement[] stackTraceElement =ex.getStackTraceElement(0);
n = stackTraceElement.length;
for (int i = 0 ;i<n;i++ )
{
ejemplo = ejemplo+ " "+stackTraceElement[i].getLineNumber()+">>"+stackTraceElement[i].getMethodName();
}
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return ejemplo;
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetMortgagePayment xmlns="http://www.webserviceX.NET/">
<Years>10</Years>
<Interest>0.7</Interest>
<LoanAmount>1000000</LoanAmount>
<AnnualTax>0.5</AnnualTax>
<AnnualInsurance>0.9</AnnualInsurance>
</GetMortgagePayment>
</soap12:Body>
</soap12:Envelope>