XML Klassenreferenz

Aufstellung aller Elemente

Öffentliche Methoden

 encode ($array)
 array_transform ($array, $depth)
 openTag ($key, $attr)
 shortTag ($key, $attr)
 closeTag ($key)

Öffentliche Attribute

 $xmlText = ''
 $root = 'xml'
 $indentChar = "\t"
 $nl = "\n"


Ausführliche Beschreibung

Multidimensional Array-to-XML.

Example: $xml = new XML(); header('Content-Type: application/xml'); echo $xml->encode( $yourBigArray ); exit;

Author: Honor� Vasconcelos, Jan Dankert

Original from: Clean XML To Array: http://www.phpclasses.org/browse/package/3598.html

License of this class: BSD-Licence.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of the Author(s) nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definiert in Zeile 42 der Datei XML.class.php.


Dokumentation der Elementfunktionen

XML::array_transform ( array,
depth 
)

private

Definiert in Zeile 95 der Datei XML.class.php.

Benutzt closeTag().

Wird benutzt von encode().

00095                                             {
00096 
00097           foreach($array as $key => $value)
00098           {
00099                $attr = array();
00100                if   ( is_numeric($key) )
00101                {
00102                     // Array-Einträge mit numerischen Index können nicht direkt in ein XML-Element
00103                     // umgewandelt werden, da nur-numerische Element-Namen nicht erlaubt sind.
00104                     // Daher verwenden wir dann 'entry' als Elementnamen.
00105                     $attr['id'] = $key;
00106                     $key = 'entry';
00107                }
00108                
00109                $indent = str_repeat($this->indentChar,$depth);
00110                
00111                if   ( empty($value) )
00112                {
00113                     $this->xmlText .= $indent.$this->shortTag($key,$attr).$this->nl;
00114                }
00115                elseif    ( is_object($value) )
00116                {
00117                     // Der Inhalt ist ein Array, daher rekursiv verzweigen.
00118                     $this->xmlText .= $indent.$this->openTag($key,$attr).$this->nl;
00119                     $prop = get_object_vars($value);
00120                     $this->array_transform($prop,$depth+1); // Rekursiver Aufruf
00121                     $this->xmlText .= $indent.$this->closeTag($key).$this->nl;
00122                }
00123                elseif    ( is_array($value) )
00124                {
00125                     // Der Inhalt ist ein Array, daher rekursiv verzweigen.
00126                     $this->xmlText .= $indent.$this->openTag($key,$attr).$this->nl;
00127                     $this->array_transform($value,$depth+1); // Rekursiver Aufruf
00128                     $this->xmlText .= $indent.$this->closeTag($key).$this->nl;
00129                }
00130                else
00131                {
00132                     // Der Inhalt ist ein einfacher Inhalt (kein Array).
00133                     $this->xmlText .= $indent.$this->openTag($key,$attr);
00134                     $this->xmlText .= $value;
00135                     $this->xmlText .= $this->closeTag($key).$this->nl;
00136                }
00137           }
00138      }

XML::closeTag ( key  ) 

Definiert in Zeile 163 der Datei XML.class.php.

Wird benutzt von array_transform().

00164      {
00165           return '</'.$key.'>';
00166      }

XML::encode ( array  ) 

Encode a array to XML.

Parameter:
Array $array
Rückgabe:
String (serialized XML)

Definiert in Zeile 80 der Datei XML.class.php.

Benutzt array_transform().

00081      {
00082           //star and end the XML document
00083           $this->xmlText = '<?xml version="1.0" encoding="utf-8"?>'.$this->nl;
00084           $this->xmlText .= '<'.$this->root.'>'.$this->nl;
00085           $this->array_transform($array,1);
00086           $this->xmlText .='</'.$this->root.'>';
00087           
00088           return $this->xmlText;
00089      }

XML::openTag ( key,
attr 
)

Definiert in Zeile 141 der Datei XML.class.php.

00142      {
00143           $tag = '<'.$key;
00144           foreach( $attr as $attr_name=>$attr_value )
00145                $tag .= ' '.$attr_name.'="'.$attr_value.'"';
00146           $tag .= '>';
00147           return $tag;
00148      }

XML::shortTag ( key,
attr 
)

Definiert in Zeile 152 der Datei XML.class.php.

00153      {
00154           $tag = '<'.$key;
00155           foreach( $attr as $attr_name=>$attr_value )
00156                $tag .= ' '.$attr_name.'="'.$attr_value.'"';
00157           $tag .= ' />';
00158           return $tag;
00159      }


Dokumentation der Datenelemente

XML::$indentChar = "\t"

Definiert in Zeile 65 der Datei XML.class.php.

XML::$nl = "\n"

Definiert in Zeile 72 der Datei XML.class.php.

XML::$root = 'xml'

Definiert in Zeile 58 der Datei XML.class.php.

XML::$xmlText = ''

Parse multidimentional array to XML.

Parameter:
array $array
Rückgabe:
String

Definiert in Zeile 50 der Datei XML.class.php.


Die Dokumentation für diese Klasse wurde erzeugt aufgrund der Datei:

Erzeugt am Thu May 14 00:55:51 2009 für OpenRat von  doxygen 1.5.8