<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OSI protocols &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/osi-protocols/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>PHP: Does SimpleXMLElement have toString() method? No, better use asXML()!</title>
		<link>/2011/10/10/php-does-simplexmlelement-have-tostring-method-no-better-use-asxml/</link>
		<comments>/2011/10/10/php-does-simplexmlelement-have-tostring-method-no-better-use-asxml/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 11:52:49 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[Computer file formats]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Markup languages]]></category>
		<category><![CDATA[Open formats]]></category>
		<category><![CDATA[OSI protocols]]></category>
		<category><![CDATA[Technical communication]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">/?p=2362</guid>
		<description><![CDATA[SimpleXML is a PHP extension that &#8220;provides a very simple and easily usable toolset to convert XML to an object&#8221; [1]. Thus you can pass a link to an XML file and SimpleXML will return an object. $xml = simplexml_load_file('path_to_the_file'); Sometimes you&#8217;d need to dump or save the entire XML as a string, but there’s &#8230; <a href="/2011/10/10/php-does-simplexmlelement-have-tostring-method-no-better-use-asxml/" class="more-link">Continue reading <span class="screen-reader-text">PHP: Does SimpleXMLElement have toString() method? No, better use asXML()!</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/07/29/php-strings-how-to-get-the-extension-of-a-file/" rel="bookmark" title="PHP Strings: How to Get the Extension of a File">PHP Strings: How to Get the Extension of a File </a></li>
<li><a href="/2010/04/20/how-to-sanitize-user-input-in-php/" rel="bookmark" title="How to Sanitize User Input in PHP?">How to Sanitize User Input in PHP? </a></li>
<li><a href="/2010/07/14/media-rss-and-zf-part-2/" rel="bookmark" title="Media RSS and ZF &#8211; Part 2">Media RSS and ZF &#8211; Part 2 </a></li>
<li><a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" rel="bookmark" title="Some Notes on the Object-oriented Model of PHP">Some Notes on the Object-oriented Model of PHP </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>SimpleXML is a PHP extension that &#8220;provides a very simple and easily usable toolset to convert XML to an object&#8221; [1]. Thus you can pass a link to an XML file and SimpleXML will return an object.</p>
<pre lang="php">$xml = simplexml_load_file('path_to_the_file');</pre>
<p>Sometimes you&#8217;d need to dump or save the entire XML as a string, but there’s no toString method! As you can see $xml is an instance of the SimpleXMLElement class.</p>
<pre lang="php">var_dump($xml); // object(SimpleXMLElement)...</pre>
<p>Actually if you take a closer look:</p>
<pre lang="php">$xml->toString();</pre>
<p>will return <strong>&#8220;Call to an undefined method toString()&#8221;</strong>, which is frustrating because the developers community is used to use toString() when converting an object into a string.</p>
<figure id="attachment_2395" style="width: 448px" class="wp-caption aligncenter"><a href="/wp-content/uploads/2011/10/XML.jpg"><img src="/wp-content/uploads/2011/10/XML.jpg" alt="XML" title="XML" width="448" height="269" class="size-full wp-image-2395" srcset="/wp-content/uploads/2011/10/XML.jpg 448w, /wp-content/uploads/2011/10/XML-300x180.jpg 300w" sizes="(max-width: 448px) 100vw, 448px" /></a><figcaption class="wp-caption-text">PHP&#039;s SimpleXML doesn&#039;t have toString() method. asXML() is used instead!</figcaption></figure>
<h2>The solution</h2>
<p>In fact there’s a method doing exactly what’s needed. This is <a title="SimpleXMLElement::asXML()" href="http://www.php.net/manual/en/simplexmlelement.asxml.php" target="_blank">SimpleXMLElement::asXML</a></p>
<p>As described in the manual page: &#8220;SimpleXMLElement::asXML — Return a well-formed XML string based on SimpleXML element&#8221; [2].</p>
<p>Besides that it does exactly what&#8217;s needed it sounds irrelevant, because you&#8217;ve an XML object and the name &#8220;asXML&#8221; doesn&#8217;t describe correctly what&#8217;s expected.</p>
<pre lang="php">$xml->asXML() // ?!</pre>
<ol>
<li><a title="SimpleXMLElement::asXML" href="http://www.php.net/manual/en/intro.simplexml.php" target="_blank">SimpleXMLElement::asXML</a></li>
<li><a title="SimpleXML Introduction" href="http://www.php.net/manual/en/intro.simplexml.php" target="_blank">SimpleXML Introduction</a></li>
</ol>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/07/29/php-strings-how-to-get-the-extension-of-a-file/" rel="bookmark" title="PHP Strings: How to Get the Extension of a File">PHP Strings: How to Get the Extension of a File </a></li>
<li><a href="/2010/04/20/how-to-sanitize-user-input-in-php/" rel="bookmark" title="How to Sanitize User Input in PHP?">How to Sanitize User Input in PHP? </a></li>
<li><a href="/2010/07/14/media-rss-and-zf-part-2/" rel="bookmark" title="Media RSS and ZF &#8211; Part 2">Media RSS and ZF &#8211; Part 2 </a></li>
<li><a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" rel="bookmark" title="Some Notes on the Object-oriented Model of PHP">Some Notes on the Object-oriented Model of PHP </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/10/10/php-does-simplexmlelement-have-tostring-method-no-better-use-asxml/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
