API15

JSimpleXMLElement/toString: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== Return a well-formed XML string based on SimpleXML element <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JSimpleXMLElement/toStri...
 
m removing red link to edit, no existant pages
Line 3: Line 3:


<span class="editsection" style="font-size:76%;">
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JSimpleXMLElement/toString|Edit Descripton]]<nowiki>]</nowiki>
<nowiki>[<! removed edit link to red link >]</nowiki>
</span>
</span>


{{Description:JSimpleXMLElement/toString}}
<! removed transcluded page call, red link never existed >


===Syntax===
===Syntax===
Line 82: Line 82:


<span class="editsection" style="font-size:76%;">
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JSimpleXMLElement/toString|Edit See Also]]<nowiki>]</nowiki>
<nowiki>[<! removed edit link to red link >]</nowiki>
</span>
</span>
{{SeeAlso:JSimpleXMLElement/toString}}
<! removed transcluded page call, red link never existed >


===Examples===
===Examples===
Line 97: Line 97:
  format= ,,,
  format= ,,,
</dpl>
</dpl>
[[Category:Archived pages API15]]

Revision as of 18:50, 12 May 2013

Description

Return a well-formed XML string based on SimpleXML element

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

toString($whitespace=true)
Parameter Name Default Value Description
$whitespace true

Returns

string

Defined in

libraries/joomla/utilities/simplexml.php

Importing

jimport( 'joomla.utilities.simplexml' );

Source Body

function toString($whitespace=true)
{
        //Start a new line, indent by the number indicated in $this->level, add a <, and add the name of the tag
        if ($whitespace) {
                $out = "\n".str_repeat("\t", $this->_level).'<'.$this->_name;
        } else {
                $out = '<'.$this->_name;
        }

        //For each attribute, add attr="value"
        foreach($this->_attributes as $attr => $value) {
                $out .= ' '.$attr.'="'.htmlspecialchars($value).'"';
        }

        //If there are no children and it contains no data, end it off with a />
        if (empty($this->_children) && empty($this->_data)) {
                $out .= " />";
        }
        else //Otherwise...
        {
                //If there are children
                if(!empty($this->_children))
                {
                        //Close off the start tag
                        $out .= '>';

                        //For each child, call the asXML function (this will ensure that all children are added recursively)
                        foreach($this->_children as $child)
                                $out .= $child->toString($whitespace);

                        //Add the newline and indentation to go along with the close tag
                        if ($whitespace) {
                                $out .= "\n".str_repeat("\t", $this->_level);
                        }
                }

                //If there is data, close off the start tag and add the data
                elseif(!empty($this->_data))
                        $out .= '>'.htmlspecialchars($this->_data);

                //Add the end tag
                $out .= '</'.$this->_name.'>';
        }

        //Return the final output
        return $out;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />