Convert XML items into a list?

I have found an XML for a football-league table, but I can’t figure out how to get each item.

Christiaan on slack sent me this:

fetch('http://iphone.gronsvartgbg.se/GAiS-v1.3.2/RssTable.ashx')
.then(function (response) {
return response.text();
})
  .then(function (response) {
  var parser = new DOMParser(),
      doc = parser.parseFromString(response, 'text/xml');

  var channel = doc.getElementsByTagName('channel')[0],
      items = channel.getElementsByTagName('item');

  console.log(channel);
  console.log(items);
});

Sadly that gives the error “DOMParser is not defined”.

Any help is appreciated :slight_smile:

Hi!

We have not bundled FuseJS with any default XML parser, but I have created an example project with you code where I use a third party XML parser :slight_smile:

<JavaScript File="Marknote/marknote.js" ux:Global="Marknote" />
<JavaScript>
    var Observable = require("FuseJS/Observable");
    var marknote = require("Marknote");
    fetch('http://iphone.gronsvartgbg.se/GAiS-v1.3.2/RssTable.ashx')
        .then(function (response) {
            response.text().then(function(text) {
                    var parser = new marknote.Parser();
                    var doc = parser.parse(text);
                    var root = doc.getRootElement();
                    var channel = root.getChildElements('channel')[0];
                    var items = channel.getChildElements('item')[0];
                    console.log(channel.toString());
                    console.log(items.toString());
                });

        }).catch(function(err) {
            console.log(err.toString());
        });
    module.exports = { };
</JavaScript>

XMLExample

Where can I download this example project?

EDIT: Found it, had to inspect element. Thank you very much! :slight_smile:

Just another question, how do I get the actual value which is inbetween the elements?

getAttributeValue doens’t work. Here is my code by the way.

function updateLeagueTable(args) {
tableItems.clear();

fetch('http://iphone.gronsvartgbg.se/GAiS-v1.3.2/RssTable.ashx&#39;)
    .then(function (response) {
    response.text().then(function(text) {

        var parser = new marknote.Parser();
        var doc = parser.parse(text);
        var root = doc.getRootElement();

        var channel = root.getChildElements('channel')[0];

        for(var i = 0; i < channel.length; i++) {
            var item = channel.getChildElements('item')[i];

            var pos = item.getAttributeValue('pos');
            var team = item.getAttributeValue('team');
            var games = item.getAttributeValue('games');
            var won = item.getAttributeValue('won');
            var draw = item.getAttributeValue('draw');
            var lost = item.getAttributeValue('lost');
            var goals = item.getAttributeValue('goals');
            var points = item.getAttributeValue('points');

            console.log(pos + ". " + team);        }

        });

    }).catch(function(err) {
        console.log(err.toString());
    });
}

For what it’s worth Lucas, I just stripped the open and close tags using javascripts replace function.

var team = (channel.getChildElements('team')[0].toString()).replace(/(<([^>]+)>)/ig,"");

Get attribute value doesn’t work as far as I’m aware.

That should work for you.

flynn.darragh@gmail.com wrote:

For what it’s worth Lucas, I just stripped the open and close tags using javascripts replace function.

var team = (channel.getChildElements('team')[0].toString()).replace(/(<([^>]+)>)/ig,"");

Get attribute value doesn’t work as far as I’m aware.

That should work for you.

Use getText() instead.

Hi.

I have tried the example. However error kept occurring whenever I compile.
The error is like ‘E0100: Package Fuse.Shapes was not found’

This is XmlTest.unoproj file in the example.

{
“RootNamespace”:"",
“Packages”: [
“Fuse.Animations”,
“Fuse.BasicTheme”,
“Fuse.Controls”,
“Fuse.Designer”,
“Fuse.Drawing”,
“Fuse.Drawing.Primitives”,
“Fuse.Effects”,
“Fuse.Elements”,
“Fuse.Entities”,
“Fuse.Gestures”,
“Fuse.Navigation”,
“Fuse.Shapes”,
“Fuse.Triggers”,
“Fuse.Reactive”,
“Fuse.Android”,
“Fuse.Desktop”,
“Fuse.iOS”,
“FuseCore”,
“Uno.Collections”,
“Uno.Geometry”
],
“Includes”: [
“*”
]
}

I deleted “Fuse.Shapes” part and tried it but then different error occurs.
‘E8001: ‘App’ does not have a property called ‘Theme’’

then I got stucked.
Is there anything I am doing wrong?? (Probably… but dunno what it is…)
Please help me…

Thank you

Here’s an updated version of the example. This now works on Fuse 0.26.*.