Location: PHPKode > scripts > XML Class > xml-class/xml.class.php
<?php

/* **************************************************************** *

Author    : Mustafa Berkan BICER
MSN       : hide@address.com
Blog      : www.mberkan.info

Details   : This class reads an XML file and returns values as we want.

Function Structures :

Function openXML($xml_file,$table_name)
	$xml_file       : This class will open this xml file. Parameter must be identified. Opens only local XML files.
	$table_name     : This class will get the records in this table. Parameter must be identified.
	
Function getFieldValue($apps_recordset, $field_name, $rowid="all-;")
	$apps_recordset : Field values will be grabbed from this recordset. Must be identified.
	$field_name     : This field's value will be returned. Must be identified.
	$rowid          : [all-; or all-br or a number]


** **************************************************************** */

class readXML{
	
	function openXML($xml_file,$table_name){

		$doc = new DOMDocument();
		$doc->load( "$xml_file" );
		
		$apps = $doc->getElementsByTagName( "$table_name" );
		
		return $apps;

	}
	
	function getFieldValue($apps_recordset, $field_name, $rowid="all-;"){

		foreach( $apps_recordset as $app )
		{
			$appids = $app->getElementsByTagName( "$field_name" );
			$appid .= $appids->item(0)->nodeValue.";";
		}
		if($rowid=="all-;"){
			return $appid;
		}elseif($rowid=="all-br"){
			$fields=split(";",$appid);
			foreach($fields as $fieldval){
				$fieldvals.=$fieldval."<br />";
			}
			return $fieldvals;
		}else{
			$fields=split(";",$appid);
			return $fields[$rowid];
		}
	}
}
?>
Return current item: XML Class