0

After receiving "day" from a text input, how can I display the <product> of the <availabilities>, ONLY from the same date using jQuery? Maybe with the use of .siblings() ?

<?xml version='1.0' encoding='iso-8859-15'?>
<timetable>
  <date>
    <day>22-01-2013</day>
    <availabilities>
      <availability>
        <starttime>10:00</starttime>
        <endtime>13:00</endtime>
        <startplace>Funchal</startplace>
        <endplace>Funchal</endplace>
        <resource>Excursões na Madeira</resource>
        <idstartplace>18</idstartplace>
        <idendplace>18</idendplace>
        <idperiodoconsumo>13289</idperiodoconsumo>
        <idproduct>23</idproduct>
        <product>EXC_SANT</product>
        <idtimeperiod>11523</idtimeperiod>
        <idavailability>3561</idavailability>
      </availability>
      <availability>
        <starttime>10:00</starttime>
        <endtime>13:00</endtime>
        <startplace>Funchal</startplace>
        <endplace>Funchal</endplace>
        <resource>Excursões na Madeira</resource>
        <idstartplace>18</idstartplace>
        <idendplace>18</idendplace>
        <idperiodoconsumo>13290</idperiodoconsumo>
        <idproduct>33</idproduct>
        <product>foot</product>
        <idtimeperiod>11524</idtimeperiod>
        <idavailability>3593</idavailability>
      </availability>
      <availability>
        <starttime>10:00</starttime>
        <endtime>13:00</endtime>
        <startplace>Funchal</startplace>
        <endplace>Funchal</endplace>
        <resource>Excursões na Madeira</resource>
        <idstartplace>18</idstartplace>
        <idendplace>18</idendplace>
        <idperiodoconsumo>13289</idperiodoconsumo>
        <idproduct>22</idproduct>
        <product>VLT_ILHA</product>
        <idtimeperiod>11523</idtimeperiod>
        <idavailability>3561</idavailability>
      </availability>
    </availabilities>
  </date>
  <date>
      ...
      </date> 
...

Here's my sucess: function:

function parseStuff(data){
    $(data).find('date').each(function(){
        var day = $(this).find('day').text();

        if (day==decodeURI(iHash[3])){
            alert('Date matches!');
        }
    });
}

I'd appreciate some help, I have no idea how to do this.. :|

2 Answers 2

1

Try this one:

var product = $(this).find('product').text();

i think you have to put this here:

if (day==decodeURI(iHash[3])){
  var product = $(this).find('product').text();
  alert('Date matches!');
}
Sign up to request clarification or add additional context in comments.

5 Comments

That will display every <product> from the XML file. I only want those whose parent is the matching date - and that's my problem!
you can try putting that in if condition where it matches
I though that would return just 1 product... facepalm Thank You!
and how can I find, for example, the <starttime>, which is a sibling of <product>?
$(this).find('starttime').text(); May be this way, depends where you want this to read.
0

This should work for you:

function parseStuff(data,toBeMatchedDate){

    productList=array();

    $(data).find('date').each(function(){


        var day = $(this).find('day').text();

        if (day==decodeURI(iHash[3]) && day==toBeMatchedDate)   //if date is matched
        {

             xmlProdcutList=$(this).find('product'); //all the products associated with this date


             $.each(function(i,thisProduct){
                         productList.push(thisProduct.text()); //store in the main array
               });

return productList;


        }
    });
}

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.