سؤال

I have a messy xml data source(which is not in my control and will not be in my control anyway).

messy xml data source

As you can see that there is ONLY ONE node which contains many lines of data.

For each line of data, there are many different fields without headers or start/close tags, so it makes parsing these lines of data into small chunks very different.

I am in Sencha Touch and using JavaScript.

The further-est step I can think is to first get the big chunk data out of the tag and then I have no idea how to do the next.

Any advice is welcome.

Thank you.

هل كانت مفيدة؟

المحلول

I would split the data into an array based on the newline \n. Then it looks like you could split on comma to get the columns. Here is an example:

        var rows = myInfo.split('\n');
        console.log(rows);
        Ext.each(rows,function(row){
           var columns = row.split(',');
           console.log(columns)
        });

I made a working fiddle here for demonstration.

Update:

On demonstration sites like JSFiddle or Sencha Fiddle you can't typically connect to a live source for an ajax request because of the same-origin policy. They take dummy data and basically fake a response.

I wasn't able to get any data back from the url you posted in the fiddle. Additionally, it looks like there may be an issue with the xml parser in sencha.fiddle. I've created a dummy example in JSFiddle of an ExtJS ajax request with the parsing information included.

http://jsfiddle.net/Ac8Fk/

The basic code would be as follows:

Ext.Ajax.request({
    url:'/echo/xml/',//the js fiddle required url for example ajax requests
    method:'POST',
    params:{//These parameters are just passed this way for JSFiddle
        xml:'<data>dsajjdsj,34343,434343\ndfgsdf,34343,43</data>',
        delay:1
    },
    success:function(response){       
        var data = response.responseXML.documentElement.textContent;
        var rows = data.split('\n');
        Ext.each(rows,function(row){
            var columns = row.split(',');
            console.log(columns);
        });
    }
});

If you can provide dummy data i can modify the example to include data more similar to your data.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top