RESOLVED: Convert HTML to Array of Objects

I have an html response containing item element tags and subelement tags within. I want to convert this to an array of item objects containing the item elements. Here is a very simplified version of the HTML:

<rss>
  <item>
    <title>Alert Number 1</title>
    <description>Description Number 1</description>
  </item>
  <item>
    <title>Alert Number 1</title>
    <description>Description Number 1</description>
  </item>
</rss>

Here is the desired JSON output:

[
    {
        "title": "Alert Number 1",
        "description": "Description Number 1"
    },
    {
        "title": "Alert Number 2",
        "description": "Description Number 2"
    }
]

I thought I'd be able to do this easily with the Edit html node but that gets me item objects with the elements combined in a string or html, rather than object elements. The simple flow below shows what I want and what I get with the html option in the Edit html node.

[{"id":"bdbbd45b058fddfe","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"69d37d2a1234967a","type":"debug","z":"bdbbd45b058fddfe","name":"Output JSON","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"output","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":200,"wires":[]},{"id":"99da6278232eb673","type":"html","z":"bdbbd45b058fddfe","name":"Get Items - HTML","property":"payload","outproperty":"output","tag":"item","ret":"html","as":"single","x":330,"y":200,"wires":[["54533185b06f155b","69d37d2a1234967a","ecf7b8348d823484"]]},{"id":"ecf7b8348d823484","type":"debug","z":"bdbbd45b058fddfe","name":"Desired JSON","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"desired","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":240,"wires":[]},{"id":"eee8c7a43f66f6b1","type":"inject","z":"bdbbd45b058fddfe","name":"Setup","props":[{"p":"payload"},{"p":"desired","v":"[{\"title\":\"Alert Number 1\",\"description\":\"Description Number 1\"},{\"title\":\"Alert Number 2\",\"description\":\"Description Number 2\"}]","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"<rss>   <item>     <title>Alert Number 1</title>     <description>Description Number 1</description>   </item>   <item>     <title>Alert Number 1</title>     <description>Description Number 1</description>   </item> </rss>","payloadType":"str","x":150,"y":200,"wires":[["99da6278232eb673"]]},{"id":"54533185b06f155b","type":"debug","z":"bdbbd45b058fddfe","name":"HTML Source","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":160,"wires":[]}]

So what is the best/easiest/proper method to achieve this?

[For those who notice this is actually an RSS parser, the feedparser node does not contain the initialization and timing control that I need. The user contrib versions with input could work but are overkill for what I am doing.]

Peter

Try feeding it through an xml node.

DOH! Yeah, that works fine. Thanks!

Peter

Excellent. Glad to be of help.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.