Back to index

awl  0.53
Classes | Namespaces | Functions
XMLElement.php File Reference

Go to the source code of this file.

Classes

class  XMLElement

Namespaces

namespace  awl
 Authentication handling class.

Functions

 BuildXMLTree ($xmltags, &$start_from)
 Rebuild an XML tree in our own style from the parsed XML tags using a tail-recursive approach.

Function Documentation

BuildXMLTree ( xmltags,
&$  start_from 
)

Rebuild an XML tree in our own style from the parsed XML tags using a tail-recursive approach.

Parameters:
array$xmltagsAn array of XML tags we get from using the PHP XML parser
intref&$start_fromA pointer to our current integer offset into $xmltags
Returns:
mixed Either a single XMLElement, or an array of XMLElement objects.

If there is only one element, return it directly, otherwise return the array of them

Definition at line 338 of file XMLElement.php.

                                                {
  $content = array();

  if ( !isset($start_from) ) $start_from = 0;

  for( $i=0; $i < 50000 && isset($xmltags[$start_from]); $i++) {
    $tagdata = $xmltags[$start_from++];
    if ( !isset($tagdata) || !isset($tagdata['tag']) || !isset($tagdata['type']) ) break;
    if ( $tagdata['type'] == "close" ) break;
    $xmlns = null;
    $tag = $tagdata['tag'];
    if ( preg_match( '{^(.*):([^:]*)$}', $tag, $matches) ) {
      $xmlns = $matches[1];
      $tag = $matches[2];
    }
    $attributes = ( isset($tagdata['attributes']) ? $tagdata['attributes'] : false );
    if ( $tagdata['type'] == "open" ) {
      $subtree = BuildXMLTree( $xmltags, $start_from );
      $content[] = new XMLElement($tag, $subtree, $attributes, $xmlns );
    }
    else if ( $tagdata['type'] == "complete" ) {
      $value = ( isset($tagdata['value']) ? $tagdata['value'] : false );
      $content[] = new XMLElement($tag, $value, $attributes, $xmlns );
    }
  }

  if ( count($content) == 1 ) {
    return $content[0];
  }
  return $content;
}