glotchimo
glotchimo

Reputation: 685

Google Apps Script - XML Parsing Issues

I'm using the ZoomInfo PersonSearch API in Google Apps Script. Within the framework, I'm using UrlFetchApp and XmlService when dealing with the query and parsing.

var response = UrlFetchApp.fetch(query);
var xml = response.getContentText();
var document = XmlService.parse(xml);

When I attempt to parse the response, I am informed that there is no DTD, however, the header and root element is as follows:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<personSearchResponse xmlns="http://partnerapi.zoominfo.com/partnerapistatic/xsd/V4">

The root element, as displayed above, includes the necessary XSD to parse the file. Why isn't XmlService recognizing this declaration?

Upvotes: 1

Views: 1337

Answers (1)

edward
edward

Reputation: 243

In case if XML-response contains namespace, you need to specify its value in the method. I see that your example has namespace: http://partnerapi.zoominfo.com/partnerapistatic/xsd/V4 and instead of getChild(name) you need to use the method: getChild(name, namespace).

var response = UrlFetchApp.fetch(query);
var xml = response.getContentText();
var document = XmlService.parse(xml);
var root = document.getRootElement();
var namespace = XmlService.getNamespace('http://partnerapi.zoominfo.com/partnerapistatic/xsd/V4');
var someChild = root.getChild('ReplaceWithChildName', namespace);

Upvotes: 1

Related Questions