I have an .xml file stored in Drive and would like to extract information using importXML(). However, it doesn\'t work when it\'s a sharable link is from Drive.
I think that there are 2 patterns.
In this case, all XML files which are used on Spreadsheet have to be shared as ANYONE_WITH_LINK and VIEW. The URL of the shared file is https://drive.google.com/uc?id=### file id ###&export=download
. So the formula is as follows.
=importXML("https://drive.google.com/uc?id=### file id ###&export=download","### XPath query ###")
In this case, the XML files which are used on Spreadsheet are not required to share, because Web Apps is deployed. But GAS is used for this case. The install of this method is as follows.
function doGet(e) {
var xml = DriveApp.getFileById(e.parameters.id).getBlob().getDataAsString();
return ContentService.createTextOutput(xml).setMimeType(ContentService.MimeType.XML);
}
The copied Current web app URL is used for importXML()
. So the formula on Spreadsheet is as follows.
=importXML("https://script.google.com/macros/s/#####/exec?id=### file id ###","### XPath query ###")
If these were not useful for you, I'm sorry.