I use xml service before.
But I got the error message about "xml is deprecated."
So I know xml
cannot be used in the future,and the XmlService
instead.
Here is my code before.
The solution comes from here.(by Mr.Justin Bicknell)
function xml_parsing(senderId) {
var fetch = UrlFetchApp.fetch
("https://home.gamer.com.tw/homeindex.php?owner=" + senderId);
var doc = Xml.parse(fetch, true);
var bodyHtml = doc.html.body.toXmlString();
var xml = UrlFetchApp.fetch(url).getContentText();
var doc_parse = XmlService.parse(xml);
var root = doc_parse.getRootElement();
}
And I remove xml
to fix it.
function xml_parsing(senderId) {
var url = "https://home.gamer.com.tw/homeindex.php?owner=" + senderId;
var fetch = UrlFetchApp.fetch(url).getContentText();
var doc_parse = XmlService.parse(fetch);
var root = doc_parse.getRootElement();
}
There is some errors about entities occured.
The entity name must immediately follow the '&' in the entity reference
So I fix the url by converting to entities type.
var url = "https://home.gamer.com.tw/homeindex.php?owner="+ senderId
There is some error,neither.
I google other document.
One said that the XmlService.parse
is strict to Html.
Because Html contains less strict standard.
(For example: tags can be an end of tags,
but xml have to double tags enveloped)
So I want to ask how to use XmlService.parse
on the situation?
Thanks!