Location: PHPKode > projects > crVCL PHP Framework > crvcl/xml.lib.php
<?php


/*

The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html or see MPL-1.1.txt in directory "license"

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.

The Initial Developers of the Original Code are: 
Copyright (c) 2003-2011, CR-Solutions (http://www.cr-solutions.net), Ricardo Cescon
All Rights Reserved.

Contributor(s): Ricardo Cescon

crVCL PHP Framework Version 2.3
*/





############################################################
if(!defined("XML_LIB")){
   define ("XML_LIB", 1);
############################################################
#require("tools.lib.php");
//-------------------------------------------------------------------------------------------------------------------------------------
class domxml2array{
//-------------------------------------------------------------------------------------------------------------------------------------
// constructor
	function domxml2array( $xml ){
		// check for file
		if ( file_exists($xml) ){
			$xml = file_get_contents( $xml );
		}

		// check for string, open in dom
		if ( is_string($xml) ){
			$xml = domxml_open_mem( $xml );
			$this->root_element = $xml->document_element();
		}

		$xml = str_replace("\r", "", $xml);
	    $xml = str_replace("\n", "", $xml);

		// check for dom-creation,
		if ( is_object( $xml ) && $xml->node_type() == XML_DOCUMENT_NODE ){
			$this->root_element = $xml->document_element();
			//$this->xml_string = $xml->dump_mem(true);
			return true;
		}

		if ( is_object( $xml ) && $xml->node_type() == XML_ELEMENT_NODE ){
			$this->root_element = $xml;
			return true;
		}

		return false;
	}
//-------------------------------------------------------------------------------------------------------------------------------------
// public
	function getResult(){
		if ( $resultDomNode = $this->root_element ){
			$array_result[ $resultDomNode->tagname() ] = $this->_recNode2Array( $resultDomNode );
			return $array_result;
		}else{
			return false;
		}
	}
//-------------------------------------------------------------------------------------------------------------------------------------
	function getEncoding(){
		preg_match("~\<\?xml.*encoding=[\"\'](.*)[\"\'].*\?\>~i",$this->xml_string,$matches);
		return ($matches[1])?$matches[1]:"";
	}
//-------------------------------------------------------------------------------------------------------------------------------------
	function getNamespaces(){
		preg_match_all("~[[:space:]]xmlns:([[:alnum:]]*)=[\"\'](.*?)[\"\']~i",$this->xml_string,$matches,PREG_SET_ORDER);
		foreach( $matches as $match ){
			$result[ $match[1] ] = $match[2];
		}
		return $result;
	}
//-------------------------------------------------------------------------------------------------------------------------------------
// private
	function _recNode2Array( $domnode ){
		if ( $domnode->node_type() == XML_ELEMENT_NODE ){
			$childs = $domnode->child_nodes();
			foreach($childs as $child)			{
				if ($child->node_type() == XML_ELEMENT_NODE){
					$subnode = false;
					$prefix = ( $child->prefix() ) ? $child->prefix().':' : '';

					// try to check for multisubnodes
					foreach ($childs as $testnode){
					  if ( is_object($testnode) ){
						if ($child->node_name() == $testnode->node_name() && $child != $testnode){
							$subnode = true;
						}
					  }
					}
					if ( is_array($result[ $prefix.$child->node_name() ]) ){
						$subnode = true;
					}

					if ($subnode == true){
						$result[ $prefix.$child->node_name() ][]	= $this->_recNode2Array($child);
					}else{
						$result[ $prefix.$child->node_name() ]	= $this->_recNode2Array($child);
					}
				}
			}

			if ( !is_array($result) ){
				// correct encoding from utf-8 to locale
				// NEEDS to be updated to correct in both ways!
				$result['#text']	=	html_entity_decode(htmlentities($domnode->get_content(), ENT_COMPAT, 'UTF-8'), ENT_COMPAT,'ISO-8859-15');
			}

			if ( $domnode->has_attributes() ){
				foreach ( $domnode->attributes() as $attrib ){
					$prefix = ( $attrib->prefix() ) ? $attrib->prefix().':' : '';
					$result["@".$prefix.$attrib->name()]	=	$attrib->value();
				}

		    }
			return $result;
		}
	}

}
//-------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
class array2domxml
{
	var $config	=	array('encoding'	=>	'ISO-8859-15',
						  'xmlns'	=>	array('ino'	=>	'http://namespaces.softwareag.com/tamino/response2')
	                );
//-------------------------------------------------------------------------------------------------------------------------------------
// constructor
	function array2domxml( $array ){
		if (!is_array($array)){return false;}
		$this->array = $array;
		$this->dom = domxml_new_doc("1.0");
	}
//-------------------------------------------------------------------------------------------------------------------------------------
// public
	function setEncoding( $enc ){
		$this->config['encoding'] = ( $enc != '' )	?	$enc	:	$this->config['encoding'];
	}
//-------------------------------------------------------------------------------------------------------------------------------------
	function addNamespaces( $assoc ){
		$this->config['xmlns'] += $assoc;
	}
//-------------------------------------------------------------------------------------------------------------------------------------
	function getResult($format = true){
		$doc_root = array_shift( array_keys($this->array) );
		$root_element = $this->dom->create_element($doc_root);
		$this->_recArray2Node($root_element, $this->array[$doc_root]);
		$this->dom->append_child($root_element);

		// check for namespaces ? add each to doc
		if ( is_array($this->used_namespaces) ){
			foreach ($this->used_namespaces as $ns){
				$root_element->add_namespace($this->config["xmlns"][ $ns ], $ns);
			}
		}

		// <b>Warning</b>:  dump_mem(): xmlDocDumpFormatMemoryEnc:  Failed to identify encoding handler for character set 'ISO-8859-15'
		return $this->dom->dump_mem($format,$this->config['encoding']);
	}
//-------------------------------------------------------------------------------------------------------------------------------------
// private
	function _recArray2Node( $parent_node, $array ){
		foreach ($array as $key => $value){
			$org_key = $key;
			list( $ns, $key ) = preg_split( '/:/', str_replace("@","",$org_key) );
			if ( !$key ){
				$key = $ns;
			}elseif ($ns == "xmlns"){
				$this->addNamespaces( array($key => $value) );
				break;
			}else{
				if ( $this->config["xmlns"][ $ns ] ){
					$this->used_namespaces[] = $ns;
					$key = $ns.":".$key;
				}else{
					die("Namespace for $ns does not exist! Use obj->addNamespaces( \$assoc ) for adding.");
				}
			}

			if (substr($org_key, 0, 1) == '@'){
				// attribute
				$parent_node->set_attribute( $key, $value );
				continue;
			}else if ( $key == '#text' || !is_array($value) ){
				// text node
				// check if valid text & not empty
				if ( $value=='0' | !empty($value) ){
					$element = $this->dom->create_text_node($value);
					$parent_node->append_child($element);
				}
				continue;
			}else{
				// child node
				// check for enumeration
				$enum = false;
				while (list( $k, $v ) = each( $value )){
					if ( is_numeric($k) ){
						// enumeration of multiple nodes
						$enum = true;
						$element = $this->dom->create_element($key);
						$this->_recArray2Node($element, $v);
						$parent_node->append_child($element);
					}
				}

				// check for enumeration
				if (  $enum == false ){
					$element = $this->dom->create_element($key);
					$this->_recArray2Node($element, $value);
					$parent_node->append_child($element);
				}
			}
		}
	}
}
//-------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
class array2xml{
	var $xml;
	var $arrays, $keys, $node_flag, $depth, $xml_parser;
//-------------------------------------------------------------------------------------------------------------------------------------
// constructor
	function array2xml($array, $header=true){
		$this->xml = "";
		if($header){
			$this->xml .= "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";
		}
		$this->xml .= $this->array_transform($array);
		return $this->xml;
	}
//-------------------------------------------------------------------------------------------------------------------------------------
// private
	function array_transform($array){
		foreach($array as $key => $value){
			if(!is_array($value)){
	 			$this->xml .= "<$key>$value</$key>";
	 		}else{
	 			$this->xml.="<$key>";
	 			$this->array_transform($value);
	 			$this->xml.="</$key>";
	 		}
		}
		return $array_text;
	}
}
//-------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
class xml2array{
//-------------------------------------------------------------------------------------------------------------------------------------
// constructor
	function xml2array($xml, $uppertags=false){
		$xml = str_replace("\r", "", $xml);
	    $xml = str_replace("\n", "", $xml);
		$this->depth=-1;
		$this->xml_parser = xml_parser_create();
		xml_set_object($this->xml_parser, $this);
		xml_parser_set_option ($this->xml_parser,XML_OPTION_CASE_FOLDING,$uppertags);
		xml_set_element_handler($this->xml_parser, "startElement", "endElement");
		xml_set_character_data_handler($this->xml_parser,"characterData");
		xml_parse($this->xml_parser,$xml,true);
		xml_parser_free($this->xml_parser);
		return $this->arrays[0];
	}
//-------------------------------------------------------------------------------------------------------------------------------------
// private
	function startElement($parser, $name, $attrs){
	   $this->keys[]=$name; // add key
	   $this->node_flag=1;
	   $this->depth++;
	}
//-------------------------------------------------------------------------------------------------------------------------------------
	function characterData($parser,$data) {
	   $key=end($this->keys);
	   $this->arrays[$this->depth][$key]=$data;
	   $this->node_flag=0; //So that we don't add as an array, but as an element
 	}
//-------------------------------------------------------------------------------------------------------------------------------------
	function endElement($parser, $name){
	   $key=array_pop($this->keys);
	   //If $node_flag==1 we add as an array, if not, as an element
	   if($this->node_flag==1){
	     $this->arrays[$this->depth][$key]=$this->arrays[$this->depth+1];
	     unset($this->arrays[$this->depth+1]);
	   }
	   $this->node_flag=1;
	   $this->depth--;
    }
}
//-------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
class xmlHelper{
	// private
	var $m_opentags = array();
	var $m_xml;
	var $m_index_parseTag = array();
	// public
	var $m_linefeed = "\r\n";
	var $m_version = '1.0';
	var $m_encoding = 'UTF-8';
	var $m_standalone = 'yes';
//-------------------------------------------------------------------------------------------------------------------------------------
   function free(){
      $this->m_opentags = NULL;
      $this->m_xml = NULL;
      $this->m_index_parseTag = NULL;
   }
//-------------------------------------------------------------------------------------------------------------------------------------
// constructor
	function xmlHelper(){
	}
//-------------------------------------------------------------------------------------------------------------------------------------
    function __destruct(){
       $this->free();
    }	
//-------------------------------------------------------------------------------------------------------------------------------------
// private
//-------------------------------------------------------------------------------------------------------------------------------------
// public
	function isBool($tag){
		$val =	$this->ParseTag($tag);
		$val = strtoupper($val);
		if(stripos($val,'TRUE') !== false){return true;}
		if(stripos($val,'YES') !== false){return true;}
		if(stripos($val,'WAHR') !== false){return true;}
		if(stripos($val,'0') === false){return true;}
		return false;
	}
//-------------------------------------------------------------------------------------------------------------------------------------
   function parseTags($tag, $pos=1){
      $tags = '';
      $tag_len = strlen($tag);
      $xml = $this->m_xml;
      
      $withpara = false;
      $p = false;
      for($i = 1; $i <= $pos; $i++){
         $withpara = false;
         $p = strpos($xml, '<'.$tag.'>');
         if($p === false){
            $p = strpos($xml, '<'.$tag.' ');
	         $withpara = true;
         }
         
         if($i < $pos){
            if($withpara){
               $xml = substr($xml, $p);
               $p = strpos($xml, '>');
               $xml = substr($xml, $p+1);
            }else{
               $xml = substr($xml, $p+$tag_len+2);
            }   
         }                  
      }

      if($p !== false){
         if($withpara){
            $xml = substr($xml, $p);
            $p = strpos($xml, '>');
            $xml = substr($xml, $p+1);
         }else{
            $xml = substr($xml, $p+$tag_len+2);
         }   

         $p = strpos($xml, '</'.$tag.'>');
         if($p !== false){
            $tags = substr($xml, 0, $p+$tag_len+3);
            $xml = substr($xml, $p+$tag_len+3);

            while(true){
               //$stags = preg_match_all('/<'.$tag.'>/', $tags, $stags);
               //$etags = preg_match_all('/<\/'.$tag.'>/', $tags, $etags);
               // changed, str_replace ist faster to count then preg_match_all
               $stags = 0;
               str_replace('<'.$tag.'>', '', $tags, $stags);
               $etags = 0;
               str_replace('</'.$tag.'>', '', $tags, $etags);
               
               if($etags > $stags){break;}

               $p = strpos($xml, '</'.$tag.'>');
               if($p !== false){
                  $tags .= substr($xml, 0, $p+$tag_len+3);
                  $xml = substr($xml, $p+$tag_len+3);
               }else{break;}
            }

         }else{$xml = '';}
      }else{$xml = '';}

      $p = strrpos($tags, '</'.$tag.'>');
      if($p !== false){
         $tags = substr($tags, 0, $p);
      }

      return $tags;
   }
//-------------------------------------------------------------------------------------------------------------------------------------
   function changeTags($tag, $val, $pos=1){
      $new_xml = '';
      $tag_len = strlen($tag);
      $xml = $this->m_xml;
   
      $p = false;
      for($i = 1; $i <= $pos; $i++){
         $p = strpos($xml, '<'.$tag.'>');         
         if($p !== false){
            $new_xml .= substr($xml, 0, $p+$tag_len+2);
            $xml = substr($xml, $p+$tag_len+2);
         }
         if($i >= $pos){            
            break;
         }
      }

      if($p !== false){
         $new_xml .= $val;         
         $tmp_xml = '';   
                                            
         while(true){
            $p = strpos($xml, '</'.$tag.'>');
            if($p !== false){         
               $tmp_xml .= substr($xml, 0, $p+$tag_len+3);
               $xml = substr($xml, $p+$tag_len+3);
            }

            //$stags = preg_match_all('/<'.$tag.'>/', $new_xml.$tmp_xml, $stags);
            //$etags = preg_match_all('/<\/'.$tag.'>/', $new_xml.$tmp_xml, $etags);                             
            // changed, str_replace ist faster to count then preg_match_all
            $stags = 0;
            str_replace('<'.$tag.'>', '', $new_xml.$tmp_xml, $stags);
            $etags = 0;
            str_replace('</'.$tag.'>', '', $new_xml.$tmp_xml, $etags);
            
            if($etags == $stags){break;} 
         }
      
         $new_xml .= '</'.$tag.'>'.$xml;
         
         $this->m_xml = $new_xml;      
      }   
           
      
      $this->m_xml = $new_xml;      
   }   
//-------------------------------------------------------------------------------------------------------------------------------------
   /**
    * get value of single tag
    *
    * @param string $tag
    * @param int $pos
    * @param bool $cdata
    * @param bool $asISO8859
    * @return string
    */
	function parseTag($tag, $tpos=1, $cdata=false, $asISO8859=false){
		$parse = ''; 
		$tag_len = strlen($tag);
	   $xml_tmp = $this->m_xml;
	   $start_pos = 1;
	   
	   if(isset($this->m_index_parseTag[$tag][$tpos-1])){
	      $trimX = $this->m_index_parseTag[$tag][$tpos-1];
	      $xml_tmp = substr($xml_tmp, $trimX);
	      $start_pos = $tpos;
	   }
	   
	   $index_pos = 0;
	   $xml_len = $this->getLength();
	   
	   for($i = $start_pos; $i <= $tpos; $i++){	       
	       $withpara = false;
	       $pos = strpos($xml_tmp, '<'.$tag.'>');
	       if($pos === false){
	          $pos = strpos($xml_tmp, '<'.$tag.' ');
	          $withpara = true;
	       }
	       if($pos === false){
	          return false;
	       }
	       
	       $xml_tmp = substr($xml_tmp, $pos);
	       if($withpara){
	          $pos = strpos($xml_tmp, '>');
	          if($pos === false){
                return false;
             }
             
             $singletag = false;
             if($xml_tmp[$pos-1] == '/'){
                $singletag = true;
             }             
             $xml_tmp = substr($xml_tmp, $pos+1);
             if($singletag){continue;}
	       }else{
	          $xml_tmp = substr($xml_tmp, $tag_len+2);
	       }
	       
	       $pos = strpos($xml_tmp, '</'.$tag.'>');	       
	       if($pos === false){
	          return false;
	       }
	       
	       $index_pos = $xml_len-strlen($xml_tmp);
	       
	       $parse = substr($xml_tmp, 0, $pos);
	       $xml_tmp = substr($xml_tmp, $pos+$tag_len+3);
	   }
	   
	   if($cdata && strlen($parse) > 0){
	      $parse = trim($parse);
	      
			if(substr($parse,0,9)=='<![CDATA['){
				$parse = substr($parse, 9);
				if(substr($parse, -3, 3) == ']]>'){
				   $parse = substr($parse,0, strlen($parse)-3);
				}
			}
		}
				
		if(strlen($parse) > 0 && (!$cdata && $asISO8859 && $this->m_encoding == 'UTF-8')){
			$parse = utf8_decode($parse);
		}
		$parse = xmlentities_decode($parse, true);
		
		$this->m_index_parseTag[$tag][$tpos] = $index_pos; 
		
		return $parse;
	}
//-------------------------------------------------------------------------------------------------------------------------------------
  /**
    * get value of tag parameter
    *
    * @param string $tag
    * @param string $para
    * @param int $pos
    * @return string
    */
	function parsePara($tag, $para, $tpos=1){
      $parse = ''; 
	   $xml_tmp = $this->m_xml;
	   
	   for($i = 1; $i <= $tpos; $i++){	       
	       $pos = strpos($xml_tmp, '<'.$tag.' ');
	       
	       if($pos === false){
	          return false;
	       }
	       
	       $xml_tmp = substr($xml_tmp, $pos);
	       
          $pos = strpos($xml_tmp, '>');
          if($pos === false){
             return false;
          }
          
          ##################################
          $parse = substr($xml_tmp, 0, $pos+1);
          
          $p = strpos($parse, ' '.$para.' ');
          if($p === false){
             $p = strpos($parse, ' '.$para.'=');           
          }
          if($p === false){
             $parse = false;
          }else{
             $parse = substr($parse, $p);    
             $p = strpos($parse, '=');
             $parse = trim(substr($parse, $p+1));                 
             $sep = ' ';
             if(substr($parse,0,1) == '"'){
                $sep = '"';
                $parse = substr($parse, 1);    
             }else if(substr($parse,0,1) == "'"){
                $sep = "'";
                $parse = substr($parse, 1);    
             }
             $p = strpos($parse, $sep);
             if($p === false){
                $parse = false;
             }else{
                $parse = substr($parse, 0, $p);                
             }
          }                              
          ##################################   
          
          $singletag = false;
          if($xml_tmp[$pos-1] == '/'){
             $singletag = true;
          }             
          $xml_tmp = substr($xml_tmp, $pos+1);
          if($singletag){continue;}
          
	       $pos = strpos($xml_tmp, '</'.$tag.'>');	       
	       if($pos === false){
	          return false;
	       }
	       	       
	       $xml_tmp = substr($xml_tmp, $pos+3);
	   }    	   
	   return $parse;
	}	
//-------------------------------------------------------------------------------------------------------------------------------------
	function changeTag($tag, $val, $pos=1){
		$s1 = '<' . $tag . '>';
		$s2 = '</' . $tag . '>';

		$xml_tmp = $this->m_xml;

		$x = 0;
		for($i = 1; $i <= $pos; $i++){
			$p = strpos($xml_tmp,$s1);
			if($p !== false){
				$p2 = strpos($xml_tmp,$s2);
				if($i == $pos){
					if($p2){
						$newxml = '';
						$newxml .= substr($this->m_xml, 0, $x+$p+strlen($s1)+1);
						$newxml .= $val;
						$newxml .= substr($this->m_xml, $x+$p2+1, strlen($this->m_xml)-$x-$p2+1);
						$this->m_xml = $newxml;
						break;
					}
				}
				$x += $p2 + strlen($s1);
				$xml_tmp = str_del($xml_tmp,0,$p2+strlen($s1)+1);
			}else{break;}
		}
	}
//-------------------------------------------------------------------------------------------------------------------------------------
	function setXML($xml){
	   if(stripos($xml,'<?xml') !== false){
	      $pos = strpos($xml, '?>');
	      if($pos !== false){
	        $vpos = stripos($xml, 'version');
	        if($vpos !== false){
	           $version = trim(substr($xml, $vpos+7));
	           $vpos = strpos($version, '=');
	           $version = trim(substr($version, $vpos+1));
	           if(left($version,1) == '"'){
	              $version = trim(substr($version, 1));
	           }
	           $vpos = strpos($version, '"');
	           if($vpos !== false){
	              $version = trim(substr($version, 0, $vpos));
	              $this->m_version = $version;
	           }
	        }
	        $epos = stripos($xml, 'encoding');
	        if($epos !== false){
	           $encoding = trim(substr($xml, $epos+8));
	           $epos = strpos($encoding, '=');
	           $encoding = trim(substr($encoding, $epos+1));
	           if(left($encoding,1) == '"'){
	              $encoding = trim(substr($encoding, 1));
	           }
	           $epos = strpos($encoding, '"');
	           if($epos !== false){
	              $encoding = trim(substr($encoding, 0, $epos));
	              $this->m_encoding = $encoding;
	           }
	        }

	        $xml = trim(substr($xml, $pos+2));
	      }
	   }
		$this->m_xml = $xml;
	}
//-------------------------------------------------------------------------------------------------------------------------------------
	function getXML($withoutDefTag=false){
	   if($withoutDefTag==true){
	      return $this->m_xml;
	   }
	   return "<?xml version=\"".$this->m_version."\" encoding=\"".$this->m_encoding."\" standalone=\"".$this->m_standalone."\"?>\r\n".$this->m_xml;
	}
//-------------------------------------------------------------------------------------------------------------------------------------
	function getLength(){
		return strlen($this->m_xml);
	}
//-------------------------------------------------------------------------------------------------------------------------------------
	function clear(){
		$this->m_xml = "";
		unset($this->m_opentags);
		$this->m_opentags = array();
	}
//-------------------------------------------------------------------------------------------------------------------------------------
	function openTag($tag, $parameters=null){
	   $this->m_xml .= "<";
	   $this->m_xml .= $tag;
	   	   
	   if(acount($parameters) > 0){   
	      reset($parameters);
         while (list($pkey, $pval) = each($parameters)) {
            $this->m_xml .= " ".$pkey.'="'.$pval.'"';
         }
	   }
	   
	   $this->m_xml .= ">";
	   $this->m_xml .= $this->m_linefeed;
      
	   //$this->m_opentags = array_merge($this->m_opentags, array(count($this->m_opentags)=>$tag)); // changed, because slow      
	   $this->m_opentags[count($this->m_opentags)] = $tag; // changed, because slow      
	}
//-------------------------------------------------------------------------------------------------------------------------------------
	function closeTag(){
	   if(count($this->m_opentags) > 0){
	      $p = count($this->m_opentags)-1;
	      $tag = $this->m_opentags[$p];
	      unset($this->m_opentags[$p]);
	      $this->m_xml .= "</";
	      $this->m_xml .= $tag;
	      $this->m_xml .= ">";
	      $this->m_xml .= $this->m_linefeed;
	   }
	}
//-------------------------------------------------------------------------------------------------------------------------------------
   /**
    * add a single tag
    *
    * @param string $tag
    * @param string $val
    * @param bool $cdata
    * @param bool $utf8trans
    * @param array $parameters
    */
	function addTag($tag, $val, $cdata=false, $utf8trans=true, $enc_umlaute=true, $parameters=null){
      $this->m_xml .= "\t<";
      $this->m_xml .= $tag;
      
      if(acount($parameters) > 0){   
	      reset($parameters);
         while (list($pkey, $pval) = each($parameters)) {
            $this->m_xml .= " ".$pkey.'="'.$pval.'"';
         }
	   }
      
      $this->m_xml .= ">";

      if(!$cdata){
         $val = xmlentities($val, $enc_umlaute);
         if($utf8trans && $this->m_encoding == "UTF-8"){
            $val = utf8_fix($val);
         }         
   	}

      if($cdata){$this->m_xml .= "<![CDATA[";}
      $this->m_xml .= $val;
   	if($cdata){$this->m_xml .= "]]>";}

      $this->m_xml .= "</";
      $this->m_xml .= $tag;
      $this->m_xml .= ">";

      $this->m_xml .= $this->m_linefeed;
   }
//-------------------------------------------------------------------------------------------------------------------------------------
   function addTags($xml){
      $this->m_xml .= $xml;
   }
//-------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
}

// for Debug
/*
$xmlret ="<?xml version=\"1.0\"?>
<ANSWER>
	<FUNCTION>pbm_getLieferanten</FUNCTION>
	<Error>0</Error>
<LIEFERANTEN>
	<id>1</id>
	<email>hide@address.com</email>
	<id>2</id>
	<email><![CDATA[hide@address.com]]></email>
</LIEFERANTEN>
<LIEFERANTEN xx='6'>
	<id>1</id>
	<email>xxxxxxxx</email>
	<id>2</id>
	<email><![CDATA[hide@address.com]]></email>
</LIEFERANTEN>
</ANSWER>";

$xml = new xmlHelper;
$xml->setXML($xmlret);
$xml->openTag("xxx");
$xml->addTag("yy","<123>");
$xml->addTag("umlaute","öäü");
$xml->closeTag("xxx");



$xml->changeTag("email","123",2);
echo $xml->ParseTag("email",2,true);

echo $xml->parseTags("LIEFERANTEN");

echo $xml->changeTags("LIEFERANTEN", "#removed#", 2);*/

//echo "<hr>";
//echo utf8_decode($xml->getXML());

//////////////////////////////////////////
/*
$xmlstr = '<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
<param>
<value>
   <array>
   <data>
      <value>
      	<int>123</int>
      </value>
      <value>
         <array>
         <data>
            <value>
            	<int>2</int>
            </value>
            <value>
            	<int>5</int>
            </value>
         </data>
         </array>
      </value>
   </data>
   </array>
</value>
</param>
</params>
</methodResponse>';

$xml = new xmlHelper;
$xml->setXML($xmlstr);
echo $xml->parseTag("data");
*/
//////////////////////////////////////////
/*
$xmlstr = file_get_contents("w:/richie.panthermedia.net/test/ex.xml");
$xml = new xmlHelper;
$xml->setXML($xmlstr);
//echo $xml->parseTag("Cube", 3);
echo $xml->parsePara("Cube", "time", 3);
*/
/*
$xml_='<?xml version = \'1.0\' encoding = \'utf-8\'?>
<opengate-database-request channel="" password="" sourceid="17" serial="29127" clientsession="2ce1d87defe4f5618e1cf4dc4683d9d4" accountid="530" iptc_encoding="utf-8" username="105983" version="2.0.23" connection="" interface_language="DE_DE" language="DE_DE" clientip="95.91.103.23" system="Windows Vista" requestid="MP2.0.23.SP1-WVista-00216B1B4064-20090507-085957376-00066==2/530==0" >
 <image_iptc imagecommandid="image01" id="image01iptc" extraiptc="1" >
  <ref sourceid="17" clientid="00000000209393" type="img" >00000000209393</ref>
 </image_iptc>
 <image direct-link="0" extraiptccommandid="image01iptc" download="0" noimageiptc="1" id="image01" resolution="1" >
  <ref sourceid="17" clientid="00000000209393" type="img" >00000000209393</ref>
 </image>
</opengate-database-request>';

$xml = new xmlHelper();      
$xml->setXML($xml_);
$xmlstr = $xml->parseTags("image");            
$xml->setXML($xmlstr);
echo $xml->parseTag("ref");
*/

############################################################
}
############################################################
?>
Return current item: crVCL PHP Framework