GetXMLTree( $fname ); if (file_exists($fname)){ $xmlstring = file_get_contents($fname); } else { echo 'FILE DOES NOT EXIST: ' . $fname; return 0; } // replace new lines in string values with pipes $xmlstring = preg_replace( "/([^>] *)\\r\\n/m", "\\1|", $xmlstring ); $langxml = $xmlparser->GetXMLTreeFromString( $xmlstring ); //echo "
";
		//print_r( $langxml );
		
		// process forms
		foreach ( $langxml['APPLICATION'][0]['FORMS'][0]['FORM'] as $form ) {
			$formID = $form["ATTRIBUTES"]["ID"];
			$array[$formID] = getValue($form["ATTRIBUTES"]["CAPTION"]);
					
			if ( count( $form['ITEM'] ) ) {
				foreach ( $form['ITEM'] as $item ) {
					if ( strval($item['ATTRIBUTES']['CLASS']) == "tcombobox" || 
						strval($item['ATTRIBUTES']['CLASS']) == "tcustomlistview" ||
						strval($item['ATTRIBUTES']['CLASS']) == "tchecklistbox" ||
						strval($item['ATTRIBUTES']['CLASS']) == "tadvancedheaderlist" ) {
						// this item is a complex (multiline) item with multiple subitems
						$array[$formID."_".$item['ATTRIBUTES']['ID']] = getValue($item['ATTRIBUTES']['ITEMSTEXT']);
					}
					else {
						$array[$formID."_".$item['ATTRIBUTES']['ID']] = getValue($item['ATTRIBUTES']['CAPTION']);
					}
				}
			}
		}
                   
		// process menu items
		foreach ( $langxml['APPLICATION'][0]['MENUITEMS'][0]['MENU'] as $menu ) {
			$menuID = $menu["ATTRIBUTES"]["ID"];
			if ( count( $menu['ITEM'] ) ) {
				foreach ( $menu['ITEM'] as $item ) {
					$array[$menuID."_".$item['ATTRIBUTES']['ID']] = getValue($item['ATTRIBUTES']['TITLE']);
				}
			}
		}
		
		// process global strings
		foreach ( $langxml['APPLICATION'][0]['STRINGS'][0]['STRING'] as $string ) {
			$stringID = $string["ATTRIBUTES"]["ID"];
			if ( count( $string['ITEM'] ) ) {
				foreach ( $string['ITEM'] as $item ) {
					$array[$stringID."_".$item['ATTRIBUTES']['ID']] = getValue($item['ATTRIBUTES']['VALUE']);
				}
			}
		}

		return $array;		
	}
	

	/* ---------------------------------------------------------------------------------------
	 SaveALang function takes a flat array of strings containing the language data and writes
	 them down into a php file as a definition of that array.
	--------------------------------------------------------------------------------------- */
	function SaveALang( $array, $fname )
	{
		if ( ($fh = fopen( $fname, "wt" ) ) === FALSE ) return -1;
		
		fprintf( $fh, " "\\\\", "\"" => "\\\"" );
		
		foreach ( $array as $key => $val ) {
			$id = strtr( $key, $replacement );
			$string = strtr( $val, $replacement );
			fprintf( $fh, '$alang["%s"] = "%s";'."\n", $id, $string );
		}
		
		fprintf( $fh, "?>" );
		fclose( $fh );  
		
		return 0;
	}
	 
	
	
	$langFN = "data.xml";
	$alangFN = "alang.html";

	if ( isset($lang) && strlen($lang) ) $langFN = $lang;
	if ( isset($alang) && strlen($alang) ) $alangFN = $alang;
	     
	// load the .XML
	$lang = LoadLang( $langFN );
	//echo "
"; print_r( $lang ); echo "
"; // save as .HTML if ( SaveALang( $lang, $alangFN ) ) echo "Unable to save the language data.
"; else echo "Language file '$langFN' successfully converted to '$alangFN'.
"; ?>