0

I'm trying to pull in an external file which contains only 2 columns but several rows, the first is just a numeric reference in ascending order and should be just skipped but the second contains value which I need to push into an array so they can be injected into the page. So far all I can get it to do is pull in all the values.

var catalogIn = [];

$.ajax({
    url: 'content-catalog.xml',
    type: 'GET',
    dataType: 'xml',
    success: function (returnedXMLResponse) {
        $(returnedXMLResponse).find('Row').each(function () {
            // loop over each cell
            $('Data', this).each(function () {
                // push row into main array
                catalogIn.push($(this).text());
            });
        })
    }
});
1

2 Answers 2

1

First of all you need to parse the xml response like

var xmlresponse = $.parseXML(returnedXMLResponse);

Then find a node by looping the xmlresponse.

var $xml = $(xmlresponse);
var $data = $xml.find("<your node>");

$data.each(function(){

    var column1= $(this).find('your column 1').text(),
     var column2= $(this).find('your column 2').text(); 
});
Sign up to request clarification or add additional context in comments.

Comments

0

Why not check against column index then decide if you should add the element to array or not

var catalogIn = [];

$.ajax({
    url: 'content-catalog.xml',
    type: 'GET',
    dataType: 'xml',
    success: function (returnedXMLResponse) {
        $(returnedXMLResponse).find('Row').each(function () {
            // loop over each cell
            $('Data', this).each(function (index) {
                if(index == 1) {
                // push row into main array
                catalogIn.push($(this).text());
                }
            });
        })
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.