good morning I'm consuming a web service through bonitasoft with the groovy editor but I have not been successful, because when I manage the xml I can not get all the information about it, I think the problem is the way I am using the getElementsByTagName but when looking for information I also found the getElementsByTagNameNs which has very similar parameters but I am not very clear about the difference between the 2, since I think knowing how to best use the tag I could consume my web service so adequate, because at the time of mapping it gives me all the information in a single String and wants me to be separated as it is in the xml annex my code any help or clarification I will be grateful.
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import java.lang.Exception;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import java.lang.StackTraceElement;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
String ejemplo = "";
String aux = "";
boolean bandera ;
// Clean response xml document
responseDocumentBody.normalizeDocument();
// Get result node
NodeList resultList = responseDocumentBody.getElementsByTagName("*");
Element resultElement = (Element) resultList.item(0);
String weatherDataAsXML = resultElement.getTextContent();
aux = aux + (Element) resultList.item(0);
XStream xstream = new XStream();
String xml = xstream.toXML(aux);
// Check for empty result
if ("Data Not Found".equalsIgnoreCase(weatherDataAsXML))
return null;
// Parse embedded XML of result
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource inputSource = new InputSource();
inputSource.setCharacterStream(new StringReader(aux));
try{ejemplo = ejemplo +"|-|";
XPath xpath=XPathFactory.newInstance().newXPath();
Document weatherDataDocument=DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputSource);
Node nodePrincipal=(Node)xpath.evaluate("/MortgageResults/MonthlyPrincipalAndInterest",weatherDataDocument,XPathConstants.NODE);
ejemplo = ejemplo +"|error?|";
if (null == nodePrincipal)
bandera = true;
ejemplo = ejemplo +"|lo hace?|";
if (bandera ==true)
{
ejemplo = ejemplo + " si hay algo ";
}else {
ejemplo = ejemplo +"no hay nadad";
}
NodeList childNodes = weatherNode.getChildNodes();
ejemplo = ejemplo +"|=)|";
NodeList ejemploNodo = weatherDataDocument.getDocumentElement();
ejemplo = ejemplo +"|=)|";
ejemplo = ejemplo + nodeToString(ejemploNodo.getTextContent().toUpperCase());
//ejemplo = ejemplo +"|=)|";
//String principal = nodeToString(nodePrincipal.getDocumentElement());//pass in the root
//String principal=nodePrincipal.getTextContent().toUpperCase();
ejemplo = ejemplo +"|=)|";
Node nodeTax=(Node)xpath.evaluate("/MortgageResults/MonthlyTax",weatherDataDocument,XPathConstants.NODE);
String tax=nodeTax.getTextContent().toUpperCase();
ejemplo = ejemplo +"|-|";
//Document weatherDataDocument = documentBuilder.parse(inputSource);
//Node weatherNode = (Node) xPath.compile(expression).evaluate(inputSource, XPathConstants.NODE);
ejemplo = ejemplo +"|-|";
// Save weather data
Map<String,String> data = new HashMap<String,String>();
ejemplo = ejemplo +"|-|";
NodeList childNodes = weatherNode.getChildNodes();
ejemplo = ejemplo +"|y|";
for (int i=0; i<childNodes.getLength(); i++)
{
Node node = childNodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE)
{
ejemplo = ejemplo +childNodes.item(i).getNodeName() + " : " +weatherNode.getFirstChild().getNodeValue();
}
}
for (int i=0; i<childNodes.getLength(); i++)
{
Node node = childNodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE)
{
String key = childNodes.item(i).getNodeName()
String value = node.getTextContent();// necesito obtener el valor de los nodos hijos
ejemplo = ejemplo + "key ->"+key + " value ->"+value ;
data.put(key, value);
Iterator it = data.entrySet().iterator();
while (it.hasNext()) {
Map.Entry e = (Map.Entry)it.next();
ejemplo = ejemplo+" "+ e.getKey() + " " + e.getValue();
}
}
}
}catch(Exception ex){
StackTraceElement[] stackTraceElement =ex.getStackTraceElement(0);
int n = stackTraceElement.length;
ejemplo = ejemplo +"---oooo---";
for (int i = 0 ;i<n;i++ )
{
ejemplo = ejemplo+ " "+stackTraceElement[i].getLineNumber()+">>"+stackTraceElement[i].getMethodName();
}
}
return ejemplo;
<MortgageResults xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.webserviceX.NET/">
<MonthlyPrincipalAndInterest>0.083785411555805267</MonthlyPrincipalAndInterest>
<MonthlyTax>0.91666666666666663</MonthlyTax>
<MonthlyInsurance>0.083333333333333329</MonthlyInsurance>
<TotalPayment>1.0837854115558052</TotalPayment>
</MortgageResults>
thanks in advance for your attention