Does anyone know why `xmlParser.fromString({ text:...
# general
r
Does anyone know why
xmlParser.fromString({ text: xml })
would return
{"name":"#document","type":"DOCUMENT_NODE","value":null,"textContent":null}
on seemingly valid xml files?
j
What your seeing is just a string representation of the document. NetSuite doesn't stringify the content of an xml document or node. The object returned from the fromString method is a valid document and can be used with xml.XPath.select to get the nodes you want.
👍 1
r
Is there a good way to validate my data if I am unable to trust me log.debug output? The output of xml.XPath.select outputs an empty array. I'm just not 100% sure if my data is loading correctly.
j
If you got an xml document back from the call to fromString I would have thought that meant it's valid but I could be wrong perhaps something is wrong with your XPath parameter can you share what your select call looks like
r
Using this xml from a http.get as an example:
Copy code
var response = https.get({
      url: '<https://www.sec.gov/cgi-bin/browse-edgar?action=getcompany&CIK=0001652044&type=&dateb=&owner=exclude&start=0&count=40&output=atom>',
      headers: {
        'Content-type': 'application/xml'
      }
    });

var xmlDocument = xml.Parser.fromString({
      text: response.body
    });

    var entries = xml.XPath.select({
      node: xmlDocument,
      xpath: '//entry'
    });

log.debug({
      title: 'XML Document',
      details: xmlDocument
    });

log.debug({
      title: 'entries',
      details: entries
    });
logging out the response.body does return a valid xml as far as I am aware
j
Try using documentElement of your xml document variable in the XPath var entries = xml.XPath.select({ node: xmlDocument.documentElement, xpath: '//entry' });
r
Hey John, documentElement doesn't seem to work either... I get back an empty array as a response. I'm stumped on what else could be..