Please could anyone help me with this, I'm stuck, I'm trying parse this XML data and insert it into a Google Sheet, I can fetch the XML correctly but after parsing, I'm getting a null with "getChild"..
This is a extract of the XML:
<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:etaWebServicesResponse xmlns:ns1="http://ws.ABC.com/ABCws.wsdl" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xsi:type="xsd:string">
<PERSONNEL>
<INSTRUCTOR>
<PERSONNEL_ID>0001</PERSONNEL_ID>
<FIRST_NAME>Mike</FIRST_NAME>
</INSTRUCTOR>
<INSTRUCTOR>
<PERSONNEL_ID>0002</PERSONNEL_ID>
<FIRST_NAME>Joanna</FIRST_NAME>
</INSTRUCTOR>
</return>
</ns1:etaWebServicesResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And I'm trying with this Google App Script
function myFunction() {
var xmlInstructor = "<?xml version='1.0' encoding='UTF-8'?><SOAP-ENV:Envelope xmlns:" +
'SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Body><etaws><operation opstype="instructor">export</operation><parameters><customercode>AAAAAAAA</customercode><accesscode>BBBBBBBBB</accesscode><username>xybvsfsddfas</username></parameters></etaws></SOAP-ENV:Body></SOAP-ENV:Envelope>';
var url = "https://ABCsystems.com/tseta/servlet/ABC?xmldata=" + xmlInstructor;
var urlx = encodeURI(url);
var XMLFetch = UrlFetchApp.fetch(urlx).getContentText();
var document = XmlService.parse(XMLFetch);
var documentPretty = XmlService.getPrettyFormat().format(document);
Logger.log("PrettyFormat:");
Logger.log(documentPretty);
Logger.log("Descendants:");
Logger.log(document.getDescendants());
var root = document.getRootElement();
Logger.log("getRootElement:" + root);
var instructors = root.getChild("PERSONNEL");
Logger.log("Personnel:" + instructors);
}
The log of document has the XML correctly as shown at the top.
The log of Descendants has the following info (first part):
[19-05-14 15:12:09:409 PDT] Descendants:
[19-05-14 15:12:09:427 PDT] [[Element: <SOAP-ENV:Envelope [Namespace: http://schemas.xmlsoap.org/soap/envelope/]/>], [Element: <SOAP-ENV:Body [Namespace: http://schemas.xmlsoap.org/soap/envelope/]/>], [Element: <ns1:etaWebServicesResponse [Namespace: http://ws.ABCsystems.com/ABC.wsdl]/>], [Element: <return/>],
, [Element: <PERSONNEL/>],
, [Element: <INSTRUCTOR/>],
, [Element: <PERSONNEL_ID/>], 0001,
, [Element: <FIRST_NAME/>], Mike,
The log of getRootElement:
[19-05-14 15:12:09:428 PDT] getRootElement:[Element: <SOAP-ENV:Envelope [Namespace: http://schemas.xmlsoap.org/soap/envelope/]/>]
and finally instructors = null, I'm not getting to drill down. Any suggestions?
var url = "https://ABCsystems.com/tseta/servlet/ABC?xmldata=" + xmlInstructor; var urlx = encodeURI(url); var XMLFetch = UrlFetchApp.fetch(urlx).getContentText();? If I misunderstood your question, I apologize.