Hi Im trying to parse an xml feed using simplexml in php. The xml feed is laid out as follows:
<Member>
<MemberType>Full</MemberType>
<JoinDate>2010-06-12</JoinDate>
<DataType>A</DataType>
<Data>
<FirstName>Ted</FirstName>
<LasttName>Smith</LasttName>
<Data1>56</Data1>
<Data2>100</Data2>
<Data3>120</Data3>
</Data>
</Member>
<Member>
<MemberType>Full</MemberType>
<JoinDate>2010-06-12</JoinDate>
<DataType>B</DataType>
<Data>
<FirstName>Ted</FirstName>
<LasttName>Smith</LasttName>
<Data1>57</Data1>
<Data2>110</Data2>
<Data3>130</Data3>
</Data>
</Member>
<Member>
<MemberType>Full</MemberType>
<JoinDate>2010-06-12</JoinDate>
<DataType>C</DataType>
<Data>
<FirstName>Ted</FirstName>
<LasttName>Smith</LasttName>
<Data4>58</Data4>
<Data5>115</Data5>
<Data6>230</Data6>
</Data>
</Member>
where the member element loops over and over again in the xml doc, but the data inside it changes. What im trying to do is enter all the data for certain members into an sql database. So ideally i want to enter this all in one line in the db. The xml feed contains different member types, like 'full' or 'associate'.
At the moment i am trying to loop through all the full members, and get all the data for this particular member. The data for each member is broken up into three parts each with a separate member tag, so above Ted Bloggs has data in three member tags, where Datatype is A, B and C
$PLF = simplexml_load_file('../XML/Members.xml');
foreach ($PLF->Root->xpath('//Member') as $member) {
if ($member->MemberType == 'Full') {
echo $member->MemberType.'<br/>';
echo $member->JoinDate.'<br />';
echo $member->DataType.'<br/>';
echo $member->Data->FirstName.'<br/>';
echo $member->Data->LastName.'<br/>';
echo $member->Data->Data1.'<br/>';
echo $member->Data->Data2.'<br/>';
echo '<br />';
}}
the code i have at the moment can only pull data from the first type (type A) in each loop, and i really want to combine all types A, B, and C into the same loop. So i can get all the data for each member like Ted Smith into one line in the DB.