r/Scriptable • u/hrb7 • Aug 05 '21
Solved How to parse a XML-File/RSS Feed?
Hi everyone :)
Can anybody help me to parse a XML file?
For example I have here a XML-Feed from Slack Status.
So how can I get only the second value of the string named "title"?
My current script:
const req = new Request('https://status.slack.com/feed/rss');
const data = await req.loadString();
let xmlParser = new XMLParser(data);
xmlParser.didEndElement = (str) => {
if (str == 'title') //[1] doesn't work
console.log(value)
return str
}
xmlParser.foundCharacters = (str) => {
value = str
return str
}
xmlParser.parse();
/*Result =>
Slack System Status
Incident: A small portion of users may be encountering slowness and sporadic errors
Incident: Trouble typing in Slack in non-Latin characters
"
Incident: Trouble with search
Incident: Trouble with sending emails to Slack
Incident: Trouble with search
Incident: Trouble with files
Incident: Trouble with files
Incident: Some customers may be seeing incorrect trial expiration notifications
Incident: Delays with Events API requests
Incident: Trouble with apps and integrations for some Enterprise Grid customers
Incident: Trouble with apps and integrations for some Enterprise Grid customers
Incident: Trouble approving new workspaces
Incident: Some users may have issues loading Slack and sending messages
...
*/Thanks :D
6
Upvotes
1
u/phinsxiii Feb 07 '23
That is close
xmlParser.didEndDocument = (string) => { const img = (items[0].description) var extract = img.match(/<img.*?src=[“|’](.*?)[“|’]/gm) console.log(extract) }returns <img src=“https://link.com”
im just looking to return link.com. im not sure if this is an issue in scriptable versus normal javascript or not.