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

Ask A Question

Stats

  • Questions 532k
  • Answers 532k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I figured the problem. the lines CGContextTranslateCTM(lineContext, 0, -500); CGContextScaleCTM(lineContext,… May 17, 2026 at 12:14 am
  • Editorial Team
    Editorial Team added an answer The basic test [ $wtf ] tests whether the string… May 17, 2026 at 12:14 am
  • Editorial Team
    Editorial Team added an answer This looks like you need to set the contentType parameter,… May 17, 2026 at 12:13 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm using a PHP script with SimpleXML to parse an XML feed. I have
I am trying to parse an RSS feed using Linq to XML like so:
I'm trying to parse this feed: http://musicbrainz.org/ws/1/artist/c0b2500e-0cef-4130-869d-732b23ed9df5?type=xml&inc=url-rels I want to grab the URLs inside
I am trying to parse an xml file using XmlReader but although I am
I'm trying to parse a RSS feed using C#, and I need to transform
I'm trying to parse an mrss feed using jquery but am having some difficulty
I'm trying to parse an RSS/Podcast feed using Beautifulsoup and everything is working nicely
I am trying to parse iTunes top movies (top songs, albums etc) RSS feed,
I'm trying to read through an xml feed I'm getting, but I can't access
I have the following XML document that I have to parse using python's minidom:

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.