admin管理员组文章数量:1399339
I am trying to parse the following XML file with Google Apps Script XmlService
:
<?xml version="1.0" encoding="UTF-8"?>
<Report Major="1" Minor="0" Revision="1">
<CoIDs> ….
Code snippet:
function parse(txt) {
var document = XmlService.parse(txt);
var root = document.getRootElement();
//...
}
When running the script, I get the error message: Content is not allowed in prolog
.
Is there a issue with the format of the XML file? How can I parse this file with Google Apps Script?
Update
I managed to solve the issue by opening the file and saving it again as UTF-8
document with Apple TextEdit. Is there any "automatic" (or code-based) way to convert a non-UTF 8
(presumably UTF-16
document) to UTF-8
before reading it with Google Apps Script?
I am trying to parse the following XML file with Google Apps Script XmlService
:
<?xml version="1.0" encoding="UTF-8"?>
<Report Major="1" Minor="0" Revision="1">
<CoIDs> ….
Code snippet:
function parse(txt) {
var document = XmlService.parse(txt);
var root = document.getRootElement();
//...
}
When running the script, I get the error message: Content is not allowed in prolog
.
Is there a issue with the format of the XML file? How can I parse this file with Google Apps Script?
Update
I managed to solve the issue by opening the file and saving it again as UTF-8
document with Apple TextEdit. Is there any "automatic" (or code-based) way to convert a non-UTF 8
(presumably UTF-16
document) to UTF-8
before reading it with Google Apps Script?
- 1 Check whether the xml file has been saved with a BOM. – RobH Commented Nov 3, 2013 at 19:55
3 Answers
Reset to default 7It is possible to choose the char set of a file when you open it in your drive, I found this info in a post answer by a Google engineer (Corey G) so even if I didn't test it I think he's a trustful source :-) .
The post is here and the code goes as follow:
DocsList.getFileById(<some id>).getBlob().getDataAsString("UTF-16");// replace by the Charset you want... UFT-8 for example.
So I guess it's worth trying... Let us know if it solves your problem.
I ran into this issue too, I fixed it by removing the BOM (Byte order mark) from the document in my editor. This fixed the problem for me. I guess the parser sees the BOM as content or something.
I had the same problem, I've downloaded Notepad++ and configured the encoding to 'Encode in UTF-8'. You can find it by opening your xml file and selecting Encoding tab -> 'Encode in UTF-8'.
It'll be effective for all xml files in the future.
Hope it finds you well.
本文标签: javascriptGoogle Apps Script How to fix quotcontent is not allowed in prologquotStack Overflow
版权声明:本文标题:javascript - Google Apps Script: How to fix "content is not allowed in prolog" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744211502a2595438.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论