Skip to content
Advertisement

Parse XML from Google Drive in Javascript (Google Scripts) [duplicate]

I would like to ask you, please, how to parse this XML file? I would like to work with a couple of child nodes.

JavaScript

My code:

JavaScript

And I receive error:

JavaScript

Even though there are no tags “meta” and the last row in xml document is 1008.

Thank you in advance!

Advertisement

Answer

Replace

JavaScript

by

JavaScript

As your script is using UrlFetchApp to retrieve a Google Drive file using a URL of the form https://drive.google.com/file/d/[fileID] your script is getting the HTML content of the file preview.

There are two possible paths, use a URL of the form https://drive.google.com/uc?export=download&id=fileID or use the Google Drive Service i.e. DriveApp.getFileById(fileID).getBlob().getDataAsString().

If you will go for using the UrlFetchApp you should make the file public or to pass the appropriate credentials., considering this the most convenient solution is to use the Google Drive Service.

Resources

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement