_xmlDoc = new DOMDocument(); $this -> _xmlTree = $this -> _xmlDoc -> createElement( $this -> _xmlRootName ); $this -> _xmlDoc -> appendChild( $this -> _xmlTree ); } public function renderXmlTree( $dataset ) { foreach ( $dataset AS $key => $data ) { $dataset = !empty( $data['dataset'] ) ? $data['dataset'] : array(); $params = !empty( $data['params'] ) ? $data['params'] : null; $xml = $this -> array2xml( $key, $dataset, $params ); $this -> addXML( $xml ); if ( !empty( $data['params'] ) && is_array( $data['params'] ) ) $this -> _xslParams = array_merge( $this -> _xslParams, $data['params'] ); } return $this -> _xmlDoc; } public function array2xml( $tagname, $data, $params = NULL ) { if ( empty( $tagname ) ) { return; } $xml = new DomDocument; $node = $xml -> createElement( $tagname ); if( !empty( $params ) ) { foreach( $params AS $key => $value ) { $value = trim( $value ); $node -> setAttribute( $key, $value ); } } if ( !empty( $data ) ) { foreach ( $data AS $data2 ) { $child = $xml -> createElement( $tagname ); if( is_array( $data2 ) ) { foreach( $data2 AS $key => $value) { $key = strtolower( $key ); if ( preg_match( "/^(-[0-9]{1,}|[0-9]{1,})$/", $value ) ) { $newnode = $xml -> appendChild( $child ); $newnode -> setAttribute( $key, $value ); } else { @$child -> appendChild( $xml -> createElement( $key, $value ) ); } } } $node -> appendChild( $child ); } } $xml -> appendChild( $node ); return $xml; } function string2xml( $tagname, $data ) { $parent = new DomDocument; $parent_node = $parent -> createElement( $tagname ); if ( !empty( $data ) ) { $tagname = strtolower( $tagname ); if ( preg_match( "/^(-[0-9]{1,}|[0-9]{1,}|([0-9]{1,}\.[0-9]{1,}))$/", $data ) ) { $newnode = $parent -> appendChild( $parent_node ); $newnode -> setAttribute( $tagname, $data ); } else { $parent_node -> appendChild( $parent -> createElement( $tagname, $data ) ); } } $parent -> appendChild( $parent_node ); return $parent; } function addXML( $xmldoc ) { $newNode = $this -> _xmlDoc -> importNode( $xmldoc -> firstChild, true ); $this -> _xmlTree -> appendChild( $newNode ); } function addAttribute( $name, $value, $nod_name ) { $name = strtolower( $name ); $xpath = new DOMXPath( $this -> xml ); $query = "//innova"; $entries = $xpath -> query( $query ); $this -> parent_node -> setAttribute( $name, $value ); } function setXslParam( $processor ) { if ( !empty( $this -> _xslParams ) ) { foreach ( $this -> _xslParams AS $name => $value ) { $name = 'g_' . $name; $processor -> setParameter( '', $name, $value ); } } } function render2xsl( $xmlDoc, $xsltFile ) { $module_xslt = new DOMDocument(); $module_xslt -> load( $xsltFile ); $processor = new XSLTProcessor(); $processor -> registerPHPFunctions(); $this -> setXslParam( $processor ); $processor -> importStylesheet( $module_xslt ); return $processor -> transformToXml( $xmlDoc ); } } ?>