SELFPHP: Version 5.8.2 Befehlsreferenz - Tutorial – Kochbuch – Forum für PHP Einsteiger und professionelle Entwickler

SELFPHP


Professional CronJob-Service

Suche



CronJob-Service    
bei SELFPHP mit ...



 + minütlichen Aufrufen
 + eigenem Crontab Eintrag
 + unbegrenzten CronJobs
 + Statistiken
 + Beispielaufrufen
 + Control-Bereich

Führen Sie mit den CronJobs von SELFPHP zeitgesteuert Programme auf Ihrem Server aus. Weitere Infos



:: Buchempfehlung ::

Websites optimieren für Google & Co.

Websites optimieren für Google & Co. zur Buchempfehlung
 

:: Anbieterverzeichnis ::

Globale Branchen

Informieren Sie sich über ausgewählte Unternehmen im Anbieterverzeichnis von SELFPHP  

 

:: Newsletter ::

Abonnieren Sie hier den kostenlosen SELFPHP Newsletter!

Vorname: 
Name:
E-Mail:
 
 

Zurück   PHP Forum > SELFPHP > PHP Entwicklung und Softwaredesign
Hilfe Community Kalender Heutige Beiträge Suchen

PHP Entwicklung und Softwaredesign Hier können strukturelle (Programmier-) Konzepte diskutiert und Projekte vorgestellt werden

Antwort
 
Themen-Optionen Ansicht
  #1  
Alt 09.06.2005, 16:06:08
Benutzerbild von dachris
dachris dachris ist offline
Junior Member
 
Registriert seit: Apr 2005
Beiträge: 401
XML-Parser Wers braucht...

Anbei ein kleiner XML-parser (z.T. von php.net) erweitert um OOPfähigkeit, php5 only

Wers braucht.....

PHP-Code:
<?php
/**

* @package XCMS
* @subpackage XCMS-CORE
* @version ID: xml.class.php, v1.0.0 alpha, 08.06.2005 22:03:34
* @author Pohl.Christoph <christoph.pohl@ki-homepage.de>
* @version v1.0.0 alpha
* @license license.html GPL
* @copyright Copyright &copy; 2005, Pohl.Christoph
* XCore intranet is a product by ki-homepage.de. 
*/
/**
* Handles the XML input and generation
* @version ID: xml.class.php, v1.0.0 alpha, 08.06.2005 22:03:34 
* @author Pohl.Christoph
*/
defined'XCMS_VALID' ) or die( 'Direct Access to this location is not allowed.' );
class 
XcmsXml {
    
    public static 
$conf_index = array();
    public static 
$conf_val;
    
        
/**
     * Get contents from XML file and insert into an array
     *
     * @param string $file
     * @param string In which stack should the araay be saved
     */
    
public static function xml2php($file,$name) {
    
       
$xml_parser xml_parser_create();
       if (!(
$fp fopen($file"r"))) {
           die(
"unable to open XML");
       }
       
$contents fread($fpfilesize($file));
       
fclose($fp);
       
xml_parse_into_struct($xml_parser$contents$arr_vals$arr_index);
       
xml_parser_free($xml_parser);
       
self::$conf_index[$name] = $arr_index;
       
self::$conf_val[$name] = $arr_vals;
    
    }
    
    
/**
     * Get back an value of the XML File
     * @param string The name of the data which is given in php2xml
     * @param string the name of the indexparameter
     * @param string which tag should be used (value or so on....)
     * @param int the specialtag (0 = the master, other are cdata and so on....whatch the array)
     */
    
    
public static function GetValue($name,$indexname,$what "value",$specialtag 0){
                 return 
self::$conf_val[$name][self::$conf_index[$name][$indexname][$specialtag]][$what];
         }
    
    
/**
     * Convert php array to XML
     *
     * @param mixed $array_haystack
     * @return string
     */
    
public static function php2xml($array_haystack) {
    
       
$xml "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
    
       if ((!empty(
$array_haystack)) AND (is_array($array_haystack))) {
    
           foreach (
$array_haystack as $xml_key => $xml_value) {
    
               switch (
$xml_value["type"]) {
                   case 
"open":
                   
$xml .= str_repeat("\t"$xml_value["level"] - 1);
                   
$xml .= "<" strtolower($xml_value["tag"]);
                   if(isset(
$xml_value["attributes"])) $xml .= parseattributes($xml_value["attributes"]);
                   
$xml .= ">\n";
                   break;
    
                   case 
"complete":
                   
$xml .= str_repeat("\t"$xml_value["level"] - 1);
                   
$xml .= "<" strtolower($xml_value["tag"]);
                   if(isset(
$xml_value["attributes"])) $xml .= parseattributes($xml_value["attributes"]);
                   
$xml .= ">" $xml_value["value"];
                   
$xml .= "</" strtolower($xml_value["tag"]);
                   
$xml .= ">\n";
                   break;
    
                   case 
"close":
                   
$xml .= str_repeat("\t"$xml_value["level"] - 1);
                   
$xml .= "</" strtolower($xml_value["tag"]);
                   
$xml .= ">\n";
                   break;
    
                   default:
                   break;
    
               }
    
           }
    
       }
    
       return 
$xml;
    
    }
    
    
/**
     * Convert php attributes array to XML
     *
     * @param mixed $attributes
     * @return string
     */
    
function parseattributes($attributes)
    {
       
$xml "";
       foreach (
$attributes as $attribute_key => $attribute_value) {
           
$xml .= sprintf(' %s="%s"'strtolower($attribute_key), $attribute_value);
       }
       return 
$xml;
    }    
    
    
    }

//Usage

//Liest die Datei ein, und speichert sie innerhalb der Klasse als array ab
XcmsXml::xml2php("meinordner/meinxmldatei.xml","mein.name");
XcmsXml::xml2php("meinordner/meinxmldatei2.xml","mein.name2");

//z.B. die Version aus der Datei 1 (mein.name) wird so ausgelesen
//Es wird nicht mehr auf die XML zugegriffen sondern nur noch auf das array

echo XcmsXml::GetValue("mein.name","VERSION"); 

//um auf die attributes zuzugreifen von XCMS-Root z.B. HOST

$Test =  XcmsXml::GetValue("mein.name","XCMS-ROOT","attributes");

echo 
$Test["HOST"];

/**
Mögliche Strings hier 
tag = Name des übergeordneten Tags
attributes = Attribute
value = Inhalt zwischen den Tags
type = was für ein Typ (open, close, cdata etc) **/

Der Type kann alternativ noch als 4 te Variable angehängt werden :-)




?>
Das ist die TestXML

HTML-Code:
<?xml version='1.0'?>
<config id="main">
	<XCMS-ROOT host="localhost" username="foo" password="bar" db="test">
		<version>1.0.0 alpha</version>
	</XCMS-ROOT>
</config>

Geändert von dachris (09.06.2005 um 16:07:12 Uhr)
Mit Zitat antworten
Antwort


Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind aus.
[IMG] Code ist aus.
HTML-Code ist aus.

Gehe zu

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
parser fehler bei mailfunc Stifler PHP Grundlagen 5 18.12.2003 15:04:05
.php Datei downloaden statt ausführen Webstylist PHP Grundlagen 12 16.04.2003 08:53:02


Alle Zeitangaben in WEZ +2. Es ist jetzt 19:12:04 Uhr.


Powered by vBulletin® Version 3.8.3 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.


© 2001-2024 E-Mail SELFPHP OHG, info@selfphp.deImpressumKontakt