Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 998701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:14:22+00:00 2026-05-16T07:14:22+00:00

Hi Im trying to parse an xml feed using simplexml in php. The xml

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:14:23+00:00Added an answer on May 16, 2026 at 7:14 am

    I use simple xml to read some remote files and loop thru them as well. This is my code:

             $sUrl      = "some url";
             $sContent  = file_get_contents($sUrl);
    
            $oXml       = new SimpleXMLElement($sContent);
    
            $aReturn    = array();
    
            foreach ($oXml->children() as $oStation)
            {
                $iRackId    = (int)$oStation->rack_id;
                $dLong      = (double)str_replace(",", ".", $oStation->longitute);
                $dLati      = (double)str_replace(",", ".", $oStation->latitude);
                $sDescription = (string)$oStation->description;
    
                $aRes   = array();
                $aRes['rack_id']        = $iRackId;
                $aRes['longitute']      = $dLong;
                $aRes['latitude']       = $dLati;
                $aRes['description']    = utf8_decode($sDescription);
    
                if ($dLong > 0 && $dLati > 0)
                    $aReturn[$iRackId]  = $aRes;
            }
    

    What I do is I put the result of the XML file into an array. Later in the code I save that data to the database as well.

    Hope this helped you. I don’t use xpath… had nothing but problems with it and didn’t had the time to sort them out. This seems to work for me though.

    Br,
    Paul Peelen

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse a jobs feed using PHP's SimpleXML. I've only used JSON
I'm trying to parse XML feed with SimpleXML, here is a chunk of the
I am trying to parse an xml feed using xpath. The feed contains categories
I'm trying to parse an RSS feed using LINQ to Xml This is the
I am trying to parse an individual element from an XML string using PHP.
Since Days i'm trying to parse a YOUTUBE-XML-Feed by using GDATA-API for iOS. http://code.google.com/intl/de-DE/apis/youtube/2.0/developers_guide_protocol_channel_search.html
I am trying to parse an RSS feed using Linq to XML like so:
I am trying to parse XML files using Nokogiri, Ruby and XPath. I usually
I'm trying to parse an XML coming from an php request URI: http://caracasfutbolclub.com/service/news.php .
I am trying to parse an XML file with python using lxml, but get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.