Hello guyes n girls!

I'm having a problem with parsing XML with PHP. So far all my tutorial experiences has lead to extreme errors or no data what so ever.

I'm working on an Anarchy Online guild site where character details and the likes will be pulled out of an XML file, parsed and put together with a biography and the likes.

Now, is there anyone who has made this before or got a nice and clean XML parsing script thats easily understandable for a novice.

An example of the XML file(s) I wish to parse can be seen here.

If you know any tutorials you think might have been usefull for this project, please post them for me here.

These are the tutorials I've tried out so far (and failed mind you):
Hands on XML by Niels Barlach

There was another tutorial but I failed to backtrack it.

Thank you so much for your help!

    Hello guyes n girls!

    I'm having a problem with parsing XML with PHP. So far all my tutorial experiences has lead to extreme errors or no data what so ever.

    I'm working on an Anarchy Online guild site where character details and the likes will be pulled out of an XML file, parsed and put together with a biography and the likes.

    Now, is there anyone who has made this before or got a nice and clean XML parsing script thats easily understandable for a novice.

    An example of the XML file(s) I wish to parse can be seen here.

    If you know any tutorials you think might have been usefull for this project, please post them for me here.

    These are the tutorials I've tried out so far (and failed mind you):
    Hands on XML by Niels Barlach

    There was another tutorial but I failed to backtrack it.

    Thank you so much for your help!

      here is something that i found... thrown together from lots of different people it looks like... just parses the document into an associative array... so you can user normal php logic on the display

      may or may not be what you need, as it only parses... but it's simple, and small, and easily understandable....

      so maybe you can take this and entend it into whatever you need...

      this isn't really a class but a static library meant to be called ala.

      XML::getTree()

      /// wrapped up all pretty by [email]ednark@linuxmail.org[/email]
      class XML
      {
          // by: [email]farinspace@hotmail.com[/email]
          function getTree( $filename ) 
          {
              $data = implode('', file($filename));
              // by: [email]waldo@wh-e.com[/email] - trim space around tags not within
              $data = eregi_replace(">"."[[:space:]]+"."<","><",$data);
              // begin the good stuff
              $p = xml_parser_create();
              // by: [email]anony@mous.com[/email] - meets XML 1.0 specification
              xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0);
              xml_parse_into_struct($p, $data, $vals, $index);
              xml_parser_free($p);
              $i      = 0;
              $tree   = array();
              $tree[] = array(
                          'tag'        => $vals[$i]['tag'],
                          'attributes' => $vals[$i]['attributes'],
                          'value'      => $vals[$i]['value'],
                          'children'   => XML::getChildrenNodes($vals, $i)
                          );
              return $tree;
          }
      
      // by: [email]farinspace@hotmail.com[/email]
      function getChildrenNodes($vals, &$i) {
          $children = array();
          $size_of_vals = sizeof($vals)
          while (++$i < $size_of_vals) {
              // compair type
              switch ($vals[$i]['type']) {
                  case 'cdata':
                      $children[] = $vals[$i]['value'];
                      break;
                  case 'complete':
                      $children[] = array(
                                      'tag'        => $vals[$i]['tag'],
                                      'attributes' => $vals[$i]['attributes'],
                                      'value'      => $vals[$i]['value']
                                      );
                      break;
                  case 'open':
                      $children[] = array(
                                      'tag'        => $vals[$i]['tag'],
                                      'attributes' => $vals[$i]['attributes'],
                                      'value'      => $vals[$i]['value'],
                                      'children'   => XML::getChildrenNodes($vals, $i)
      
                                      );
                      break;
                  case 'close':
                      return $children;
              } /// switch
          } /// while
      } /// getChildrenNodes
      
      }
      
      
      
        Write a Reply...