我想問你,如何決議這個 XML 檔案?我想使用幾個子節點。
<are:Ares_odpovedi xmlns:are="http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_answer_vreo/v_1.0.0" odpoved_datum_cas="2022-05-09T15:00:10" odpoved_pocet="1" odpoved_typ="Vypis_VREO" vystup_format="XML" xslt="klient" validation_XSLT="http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_odpovedi.xsl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_answer_vreo/v_1.0.0 http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_answer_vreo/v_1.0.0/ares_answer_vreo.xsd" Id="ares">
<are:Odpoved>
<are:Pomocne_ID>0</are:Pomocne_ID>
<are:Vysledek_hledani>
<are:Kod>1</are:Kod>
</are:Vysledek_hledani>
<are:Pocet_zaznamu>1</are:Pocet_zaznamu>
<are:Vypis_VREO>
<are:Uvod>
<are:Nadpis>Vypis z ve?ejného rejst?íku v ARES - elektronicky opis</are:Nadpis>
<are:Aktualizace_DB>2022-05-09</are:Aktualizace_DB>
<are:Datum_vypisu>2022-05-09</are:Datum_vypisu>
<are:Cas_vypisu>15:00:09</are:Cas_vypisu>
<are:Typ_vypisu>aktualni</are:Typ_vypisu>
</are:Uvod>
...
我的代碼:
var xml = UrlFetchApp.fetch("https://drive.google.com/file/d/[fileID]").getContentText();
var data = XmlService.parse(xml);
Logger.log(data.type);
我收到錯誤:
Exception: Error on line 1257: The element type "meta" must be terminated by the matching end-tag "</meta>".
即使沒有標簽“元”并且 xml 檔案中的最后一行是 1008。
先感謝您!
uj5u.com熱心網友回復:
代替
var xml = UrlFetchApp.fetch("https://drive.google.com/file/d/[fileID]").getContentText();
經過
var xml = DriveApp.getFileById(fileID).getBlob().getDataAsString();
由于您的腳本使用 UrlFetchApp 使用表單的 URL 檢索 Google Drive 檔案,因此https://drive.google.com/file/d/[fileID]您的腳本正在獲取檔案預覽的 HTML 內容。
有兩種可能的路徑,使用表單的 URLhttps://drive.google.com/uc?export=download&id=fileID或使用 Google Drive Service,即DriveApp.getFileById(fileID).getBlob().getDataAsString().
如果您打算使用,UrlFetchApp您應該公開檔案或傳遞適當的憑據。考慮到這一點,最方便的解決方案是使用 Google Drive Service。
資源
- 使用 Apps 腳本讀取 Google Drive 上的 xml 檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/471404.html
上一篇:如何讓MathJax更快?
