function toArray()
    {
        $out = array ();

        $attributes = $this->attribute( 'attributes' );
        if ( count( $attributes ) )
        {
            $out['attributes'] = $attributes;
        }

        $children = $this->attribute( 'children' );
        foreach( $children as $name => $value )
        {
            if ( is_object( $value ) )
            {
                $out['children'][$name] = $value->toArray();
            }
            else if ( is_array( $value ) )
            {
                foreach( $value as $key => $val )
                {
                    if ( is_object( $val ) )
                    {
                        $value[$key] = $val->toArray();
                    }
                }
                $out['children'][$name] = $value;
            }
            else
            {
                $out['children'][$name] = $value;
            }
        }

        if ( !count( $children ) )
        {
            $textContent = $this->attribute( 'textContent' );
            if ( $textContent != '' )
            {
                $out['textContent'] = $textContent;
            }
        }

        return $out;
    }