API16

JRegistryFormatXML/objectToString: Difference between revisions

From Joomla! Documentation

m clean up
m preparing for archive only
 
Line 6: Line 6:




{{subst:Description:JRegistryFormatXML/objectToString}}
 


===Syntax===
===Syntax===
Line 55: Line 55:




{{subst:SeeAlso:JRegistryFormatXML/objectToString}}
 


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=objectToString
  category=objectToString
  category=JRegistryFormatXML
  category=JRegistryFormatXML
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>

Latest revision as of 02:00, 25 March 2017

Description

Converts an object into an XML formatted string. If more than two levels of nested groups are necessary, since INI is not useful, XML or another format should be used.




Syntax

objectToString($object, $params)
Parameter Name Default Value Description
$object Data source object.
$params Options used by the formatter.

Returns

string XML formatted string.

Defined in

libraries/joomla/registry/format/xml.php

Importing

jimport( 'joomla.registry.format.xml' );

Source Body

public function objectToString($object, $params)
{
        $depth = 1;
        $retval = "<?xml version=\"1.0\" ?>\n<config>\n";
        foreach (get_object_vars($object) as $key=>$item) {
                if (is_object($item)) {
                        $retval .= "\t<group name=\"".$key."\">\n";
                        $retval .= $this->_buildXMLstringLevel($item, $depth+1);
                        $retval .= "\t</group>\n";
                } else {
                        $retval .= "\t<entry name=\"".$key."\">".$item."</entry>\n";
                }
        }
        $retval .= '</config>';
        return $retval;
}



Examples

Code Examples