% まず各投稿は <entry></entry>
allListitems = xDoc.getElementsByTagName(‘entry’);
% アイテム数だけ配列を確保
title = strings(allListitems.getLength,1); % タイトル
url = strings(allListitems.getLength,1); % URL
author = strings(allListitems.getLength,1); % 投稿者
updated = strings(allListitems.getLength,1); % 最終更新日時
% 各アイテムから title, url, author 情報を出します。
for k = 0:allListitems.getLength-1
thisListitem = allListitems.item(k);
% Get the title element
thisList = thisListitem.getElementsByTagName(‘title’);
thisElement = thisList.item(0);
% The text is in the first child node.
title(k+1) = string(thisElement.getFirstChild.getData);
% Get the link element
thisList = thisListitem.getElementsByTagName(‘link’);
thisElement = thisList.item(0);
% The url is one of the attributes
url(k+1) = string(thisElement.getAttributes.item(0));
% Get the author element
thisList = thisListitem.getElementsByTagName(‘author’);
thisElement = thisList.item(0);
childNodes = thisElement.getChildNodes;
author(k+1) = string(childNodes.item(1).getFirstChild.getData);
% Get the <updated>2020-04-18T16:40:12Z</updated>
thisList = thisListitem.getElementsByTagName(‘updated’);
thisElement = thisList.item(0);
updated(k+1) = string(thisElement.getFirstChild.getData);
end
% 日時データは datetime 型に変換しておきます。
updated_at = datetime(updated,‘InputFormat’, “uuuu-MM-dd’T’HH:mm:ss’Z”);
updated_at.Format = ‘uuuu-MM-dd HH:mm:ss’;
% URL は以下の形になっているので、
% href=”https://www.mathworks.com/matlabcentral/answers/477845-bode-simulink-360″
url = extractBetween(url,“href=”””,“”””); % URL 部分だけ取得
entryID = double(extractBetween(url,“answers/”,“-“)); % 投稿IDを別途確保
Comments
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.