Get attribute value of parent node

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • npm
    New Member
    • Apr 2007
    • 57

    Get attribute value of parent node

    I'm trying to list the 10 most recent programs from my XML file (in a dropdown menu). In my PHP code, I'm having trouble accessing/echoing part of the attribute (ym) of the parent element (month) of each show.

    XML:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <shows>
    <month ym="201411">
      <show>
        <dt>26</dt>
        <wd>Wednesday</wd>
      </show>
      <show>
        <dt>25</dt>
        <wd>Tuesday</wd>
      </show>
      <!-- etc. -->
    </month>
    <month ym="201410">
      <show>
        <dt>31</dt>
        <wd>Friday</wd>
      </show>
      <show>
        <dt>30</dt>
        <wd>Thursday</wd>
      </show>
      <!-- etc. -->
    </month>
    </shows>
    PHP:
    Code:
    $xml = simplexml_load_file("../../../programarchive.xml");
    $show = $xml->xpath("//show");
    $i = 0;
    while ($i<10) {
    echo "<option value='" . $show[$i]->wd . ", " . substr(PROBLEM IS HERE,-2) . "/" . $show[$i]->dt . "'>" . substr(PROBLEM IS HERE,-2) . "</option>\n\t\t\t\t\t\t";
    $i++;
    }
    I'm trying to echo the month during which each program aired (11 or 10, based on the sample above). So the value of each option in the dropdown would have this format:

    Code:
    <option value='Wednesday, 11/26'>Wednesday, 11/26</option>
    <option value='Tuesday, 11/25'>Tuesday, 11/25</option>
    And so on... this is what I've tried that's close to what I need, but it keeps giving me "Array" instead of "11" or "10":
    Code:
    echo "<option value='" . $show[$i]->wd . ", " . $show[$i]->xpath("../@ym") . "/" . $show[$i]->dt . "'>" . $show[$i]->wd . ", " . $show[$i]->dt . "</option>\n\t\t\t\t\t\t";
    Thanks...
    Last edited by npm; Dec 27 '14, 03:52 AM. Reason: I accidentally submitted it before I was finished. Whoops...
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    #2
    hi
    what is the output that is appearing on the front where you are rendering this dropdown, can you please paste here ?.
    Regards,
    Omer Aslam

    Comment

    Working...