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

  • Home
  • SEARCH
  • 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 8920717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:20:52+00:00 2026-06-15T06:20:52+00:00

I am having an issue wrapping my head around the SimpleXML syntax. I am

  • 0

I am having an issue wrapping my head around the SimpleXML syntax.

I am trying to echo a few pieces of info I pull out of a larger xml document based on a predefined value DELN:

$mytimes= simplexml_load_file('http://www.bart.gov/dev/eta/bart_eta.xml');


$freemont = $mytimes->station->abbr[DELN]->eta->destination[freemont]->estimate;
$millbrae = $mytimes->station->abbr[DELN]->eta->destination[millbrae]->estimate;
$richmond = $mytimes->station->abbr[DELN]->eta->destination[richmond]->estimate;

My XML:

<station>
<name>El Cerrito del Norte</name>
   <abbr>DELN</abbr>
   <date>11/30/2012</date>
   <time>07:41:02 AM PST</time>
    <eta>
         <destination>Fremont</destination>
         <estimate>14 min, 29 min, 44 min</estimate>
    </eta>
    <eta>
          <destination>Millbrae</destination>
          <estimate>6 min, 21 min, 36 min</estimate>
    </eta>
    <eta>
          <destination>Richmond</destination>
          <estimate>4 min, 10 min, 17 min</estimate>
    </eta>
</station>

Let me know if I need to provide more info. Thanks.

  • 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-06-15T06:20:53+00:00Added an answer on June 15, 2026 at 6:20 am

    First – I suppose you’re not defining DELN constant, probably you should use a string (‘DELN’). Same with freemont, millbrae and richmont. The problem is not only SimpleXML syntax, basically its misunderstanding of XML structure that you want to read (abbr is not in straight path with eta, same with destination and estimate). Anyway – xpath will be your friend here:

    $fremont = $mytimes->xpath('//station/eta/estimate[../../abbr/text()=\'DELN\' and ../destination/text()=\'Fremont\']');
    $millbrae = $mytimes->xpath('//station/eta/estimate[../../abbr/text()=\'DELN\' and ../destination/text()=\'Millbrae\']');
    $richmond = $mytimes->xpath('//station/eta/estimate[../../abbr/text()=\'DELN\' and ../destination/text()=\'Richmond\']');
    

    then you can do:

    foreach ($fremont as $value) echo $value;
    

    or just

    if (count($fremont) > 0) echo $fremont[0];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having an issue wrapping my head around how to hook up a
I'm having a bit of an issue wrapping my head around something. I'm currently
I'm having a slight issue wrapping my head around on how to set up
I'm having trouble wrapping my head around this issue. I have a business model
I am currently having some trouble wrapping my head around this issue. I had
I'm new to backbone.js and having some trouble wrapping my head around an issue
I'm currently having an issue wrapping my brain around the notion of converting my
Having a bit of trouble wrapping my head around Qtimer this morning. Here's the
Im having a hard time wrapping my head around a design flaw and I'm
I'm having some issues wrapping my head around the concept of classloading, I've been

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.