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
-
<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>
<Gender>
M
</Gender>
<Party Id="4">
Conservative
</Party>
<House>
Commons
</House>
<MemberFrom>
North West Leicestershire
</MemberFrom>
<HouseStartDate>
2010-05-06T00:00:00
</HouseStartDate>
<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/>
</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/>
</Address>
</Addresses>
</Member>
</Members>
This is where I'm at so far and I'm struggling to focus on those specific areas;
- $.ajax({
- type: 'GET',
- url: 'http://data.parliament.uk/membersdataplatform/services/mnis/members/query/fymp=LE65+1WF/Addresses/',
- dataType: 'xml',
- success: function (xml) {
- $(xml).find("Members").slice( ).each(function (i,j) {
- console.log($(j).attr("id"));
- console.log($(j).find("name").attr("lang"));
- var DisplayAs = $(this).find("DisplayAs").text();
- var Party = $(this).find('Party').text()
- //Working on
- var website = $(this).find(' Address1').text();
- // var address = $(this).find('Address.4.Address1').text()
- //display
- $('.mp_data').append('<h1>' + DisplayAs + '</h1> ' + Party + ' <br> ' + website + ' ');
- });
- }
- });
Any ideas how to be specific?