Web Analytics Made Easy -
StatCounter xml - CodingForum

Announcement

Collapse
No announcement yet.

xml

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • xml

    ok, i've been racking my brain for a few hours. I've got something outputting from cpanel and its xml, but SimplexmlElement gives me an error that its not valid XML, so I'm trying to format it to read it. Keep in mind I cannot alter the actual output as its shared hosting and that part is inaccesibile.

    XML output for a listpops function (lists email accounts in cpanel)
    PHP Code:
      <cpanelresult>
        <
    apiversion>2</apiversion>
        <
    data>
          <
    email>sales@mysite.com</email>
          <
    login>sales@mysite.com</login>
        </
    data>
        <
    data>
          <
    email>service@mysite.com</email>
          <
    login>service@mysite.com</login>
        </
    data>
      </
    cpanelresult
    I'm trying to list each <email> result as a variable.

    Thanks for any help

  • #2
    Try this:

    PHP Code:
    <?php

    // Enter your XML (URL) file path/name here...
    $file "yourfile.xml";

    // Get XML 
    $xml=simplexml_load_file($file);

    // Loop
    foreach ($xml->cpanelresult->data as $item) { 
    echo
    "
    Email: 
    {$item->email} <br  />
    Login: 
    {$item->login}
    "
    ;
    }

    ?>

    Comment


    • #3
      Thanks, got me on the right track, below is what I used in case anyone needs

      PHP Code:
      <?
      // Enter your XML (URL) file path/name here...
      $file "http://mysite.com/myFile.php";

      // Get XML 
      $xml=simplexml_load_file($file);

      // Loop
      foreach ($xml->data as $item) { 
      echo
      "
      Email: 
      {$item->email} <br  />
      Login: 
      {$item->login} <br /><br />
      "
      ;
      }
      ?>

      Comment

      Working...
      X