Pull specific areas of data from XML

Pull specific areas of data from XML

This is the XML file and I can pull through all of the data, however I want to be more specific, for example there are multiple addresses and I want address1 from id=4 and then email from id=6
  1. <Members>
    <Member Member_Id="4133" Dods_Id="62823" Pims_Id="5593" Clerks_Id="1220">
    <DisplayAs> Andrew Bridgen </DisplayAs>
    <ListAs> Bridgen, Andrew </ListAs>
    <FullTitle> Andrew Bridgen MP </FullTitle>
    <LayingMinisterName/>
    <DateOfBirth> 1964-10-28T00:00:00 </DateOfBirth>
    <DateOfDeath xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
    <Gender> M </Gender>
    <Party Id="4"> Conservative </Party>
    <House> Commons </House>
    <MemberFrom> North West Leicestershire </MemberFrom>
    <HouseStartDate> 2010-05-06T00:00:00 </HouseStartDate>
    <HouseEndDate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
    <CurrentStatus Id="0" IsActive="True">
    <Name> Current Member </Name>
    <Reason/>
    <StartDate> 2017-06-08T00:00:00 </StartDate>
    </CurrentStatus>
    <Addresses>
    <Address Type_Id="6">
    <Type> Website </Type>
    <IsPreferred> False </IsPreferred>
    <IsPhysical> False </IsPhysical>
    <Note/>
    <Address1> http://www.andrewbridgen.com/ </Address1>
    </Address>
    <Address Type_Id="4">
    <Type> Constituency </Type>
    <IsPreferred> False </IsPreferred>
    <IsPhysical> True </IsPhysical>
    <Note/>
    <Address1> Unit 10, The Courtyard </Address1>
    <Address2> Whitwick Business Park </Address2>
    <Address3> Coalville </Address3>
    <Address4> Leicestershire </Address4>
    <Address5/>
    <Postcode> LE67 4JP </Postcode>
    <Phone> 01530 417736; Fax 01530 560896 </Phone>
    <Fax/>
    <OtherAddress/>
    </Address>
    <Address Type_Id="1">
    <Type> Parliamentary </Type>
    <IsPreferred> False </IsPreferred>
    <IsPhysical> True </IsPhysical>
    <Note/>
    <Address1> House of Commons </Address1>
    <Address2/>
    <Address3/>
    <Address4/>
    <Address5> London </Address5>
    <Postcode> SW1A 0AA </Postcode>
    <Phone> 020 7219 7238 </Phone>
    <Fax> 020 7219 6819 </Fax>
    <OtherAddress/>
    </Address>
    <Address Type_Id="7">
    <Type> Twitter </Type>
    <IsPreferred> False </IsPreferred>
    <IsPhysical> False </IsPhysical>
    <Note/>
    <Address1> https://twitter.com/ABridgen </Address1>
    </Address>
    </Addresses>
    </Member>
    </Members>
This is where I'm at so far and I'm struggling to focus on those specific areas;
  1. $.ajax({
  2.     type: 'GET',
  3.     url: 'http://data.parliament.uk/membersdataplatform/services/mnis/members/query/fymp=LE65+1WF/Addresses/',
  4.     dataType: 'xml',
  5.     success: function (xml) {
  6.         $(xml).find("Members").slice( ).each(function (i,j) {

  7.             console.log($(j).attr("id"));
  8.             console.log($(j).find("name").attr("lang"));

  9.             var DisplayAs = $(this).find("DisplayAs").text();
  10.             var Party = $(this).find('Party').text()
  11.             //Working on
  12.             var website = $(this).find(' Address1').text();
  13.             // var address = $(this).find('Address.4.Address1').text()

  14.             //display
  15.             $('.mp_data').append('<h1>' + DisplayAs + '</h1> ' + Party + ' <br> ' + website + ' ');

  16.         });
  17.     }
  18. });

Any ideas how to be specific?
    • Topic Participants

    • sam