<?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>Mukesh Chapagain&#039;s Blog &#187; XML</title>
	<atom:link href="http://blog.chapagain.com.np/category/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.chapagain.com.np</link>
	<description>PHP Magento jQuery SQL Wordpress Joomla Programming &#38; Tutorial</description>
	<lastBuildDate>Tue, 07 Feb 2012 00:54:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Magento: Read config XML nodes</title>
		<link>http://blog.chapagain.com.np/magento-read-config-xml-nodes/</link>
		<comments>http://blog.chapagain.com.np/magento-read-config-xml-nodes/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 11:08:50 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[node]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=667</guid>
		<description><![CDATA[Here, I will be showing you how you can read XML nodes from config.xml file of your module. It&#8217;s through the Magento way with Mage::getConfig()->getNode() function. :) Here is the XML code of my config.xml file. I will be reading the nodes of this XML file. Here is the code to read the node of [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-read-write-xml/' rel='bookmark' title='Permanent Link: Magento: Read Write XML'>Magento: Read Write XML</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-list-of-all-modules-programmatically/' rel='bookmark' title='Permanent Link: Magento: How to get list of all modules programmatically?'>Magento: How to get list of all modules programmatically?</a></li>
<li><a href='http://blog.chapagain.com.np/php-read-write-xml-with-simplexml/' rel='bookmark' title='Permanent Link: PHP : Read Write Xml with SimpleXML'>PHP : Read Write Xml with SimpleXML</a></li>
<li><a href='http://blog.chapagain.com.np/php-read-write-xml-with-domdocument/' rel='bookmark' title='Permanent Link: PHP : Read Write Xml with DOMDocument'>PHP : Read Write Xml with DOMDocument</a></li>
<li><a href='http://blog.chapagain.com.np/magento-create-read-delete-cookie/' rel='bookmark' title='Permanent Link: Magento: Create, read, delete cookie'>Magento: Create, read, delete cookie</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Here, I will be showing you how you can read XML nodes from <strong>config.xml</strong> file of your module. It&#8217;s through the Magento way with <strong>Mage::getConfig()->getNode()</strong> function. :)</p>
<p>Here is the XML code of my <strong>config.xml</strong> file. I will be reading the nodes of this XML file.</p>
<p><span id="more-667"></span></p>
<pre class="brush: xml; title: ; notranslate">
&lt;default&gt;
	&lt;catalog&gt;
		&lt;mypage&gt;
			&lt;name&gt;myname&lt;/name&gt;
			&lt;age&gt;100&lt;/age&gt;
			&lt;address_one&gt;earth&lt;/address_one&gt;
		&lt;/mypage&gt;
	&lt;/catalog&gt;
&lt;/default&gt;
</pre>
<p>Here is the code to read the node of the above XML file. Here, &#8216;<strong>catalog/mypage</strong>&#8216; is parent nodes path. It depends upon XML node layout.</p>
<pre class="brush: php; title: ; notranslate">
// prints 'myname'
echo Mage::getConfig()-&gt;getNode('catalog/mypage')-&gt;name;

// prints '100'
echo Mage::getConfig()-&gt;getNode('catalog/mypage')-&gt;age;

// prints 'earth'
echo Mage::getConfig()-&gt;getNode('catalog/mypage')-&gt;address_one;
</pre>
<p>Hope this helps and thanks for reading.</p>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=667&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/magento-read-write-xml/' rel='bookmark' title='Permanent Link: Magento: Read Write XML'>Magento: Read Write XML</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-get-list-of-all-modules-programmatically/' rel='bookmark' title='Permanent Link: Magento: How to get list of all modules programmatically?'>Magento: How to get list of all modules programmatically?</a></li>
<li><a href='http://blog.chapagain.com.np/php-read-write-xml-with-simplexml/' rel='bookmark' title='Permanent Link: PHP : Read Write Xml with SimpleXML'>PHP : Read Write Xml with SimpleXML</a></li>
<li><a href='http://blog.chapagain.com.np/php-read-write-xml-with-domdocument/' rel='bookmark' title='Permanent Link: PHP : Read Write Xml with DOMDocument'>PHP : Read Write Xml with DOMDocument</a></li>
<li><a href='http://blog.chapagain.com.np/magento-create-read-delete-cookie/' rel='bookmark' title='Permanent Link: Magento: Create, read, delete cookie'>Magento: Create, read, delete cookie</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/magento-read-config-xml-nodes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Magento: Read Write XML</title>
		<link>http://blog.chapagain.com.np/magento-read-write-xml/</link>
		<comments>http://blog.chapagain.com.np/magento-read-write-xml/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 04:15:52 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[simplexml]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=585</guid>
		<description><![CDATA[I will be using Varien_Simplexml_Element class to read write xml nodes. The path to this class file is lib/Varien/Simplexml/Element.php Here is a sample XML file which I am going to read through Magento code. I will also be adding an XML node to the following XML data. Here is the Magento/PHP code to read the [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/php-read-write-xml-with-simplexml/' rel='bookmark' title='Permanent Link: PHP : Read Write Xml with SimpleXML'>PHP : Read Write Xml with SimpleXML</a></li>
<li><a href='http://blog.chapagain.com.np/php-read-write-xml-with-domdocument/' rel='bookmark' title='Permanent Link: PHP : Read Write Xml with DOMDocument'>PHP : Read Write Xml with DOMDocument</a></li>
<li><a href='http://blog.chapagain.com.np/magento-read-config-xml-nodes/' rel='bookmark' title='Permanent Link: Magento: Read config XML nodes'>Magento: Read config XML nodes</a></li>
<li><a href='http://blog.chapagain.com.np/php-read-write-csv/' rel='bookmark' title='Permanent Link: PHP: Read Write CSV'>PHP: Read Write CSV</a></li>
<li><a href='http://blog.chapagain.com.np/magento-helper-data-not-found-error/' rel='bookmark' title='Permanent Link: Magento: Helper Data not found error'>Magento: Helper Data not found error</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I will be using <strong>Varien_Simplexml_Element</strong> class to read write xml nodes. The path to this class file is <strong>lib/Varien/Simplexml/Element.php</strong></p>
<p>Here is a sample XML file which I am going to read through Magento code. I will also be adding an XML node to the following XML data. </p>
<p><span id="more-585"></span></p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;config&gt;
    &lt;modules&gt;
        &lt;MyNamespace_MyModule&gt;
            &lt;version&gt;0.1.0&lt;/version&gt;
        &lt;/MyNamespace_MyModule&gt;
    &lt;/modules&gt;
    &lt;frontend&gt;
        &lt;routers&gt;
            &lt;mymodule&gt;
                &lt;use&gt;standard&lt;/use&gt;
                &lt;args&gt;
                    &lt;module&gt;MyNamespace_MyModule&lt;/module&gt;
                    &lt;frontName&gt;mymodule&lt;/frontName&gt;
                &lt;/args&gt;
            &lt;/mymodule&gt;
        &lt;/routers&gt;
        &lt;layout&gt;
            &lt;updates&gt;
                &lt;mymodule&gt;
                    &lt;file&gt;mymodule.xml&lt;/file&gt;
                &lt;/mymodule&gt;
            &lt;/updates&gt;
        &lt;/layout&gt;
    &lt;/frontend&gt;
&lt;/config&gt;
</pre>
<p>Here is the Magento/PHP code to read the XML data. I have kept the XML file in the root directory of Magento installation. The XML file is named <strong>test.xml</strong>. At first, the XML file is loaded and then it&#8217;s node are read with <strong>getNode </strong>function. Then, I have printed the result.</p>
<pre class="brush: php; title: ; notranslate">
$xmlPath = Mage::getBaseDir().DS.'test.xml';
$xmlObj = new Varien_Simplexml_Config($xmlPath);
$xmlData = $xmlObj-&gt;getNode();
echo &quot;&lt;pre&gt;&quot;; print_r($xmlData); echo &quot;&lt;/pre&gt;&quot;;
</pre>
<p>You can add node with the <strong>setNode </strong>function. Here, I have set a node inside the node &#8216;modules&#8217;. The name of my new node is &#8216;mukesh&#8217; and it&#8217;s value is &#8216;chapagain&#8217;.</p>
<pre class="brush: php; title: ; notranslate">
$xmlPath = Mage::getBaseDir().DS.'test.xml';
$xmlObj = new Varien_Simplexml_Config($xmlPath);

$xmlObj-&gt;setNode('modules/mukesh','chapagain');

$xmlData = $xmlObj-&gt;getNode()-&gt;asNiceXml();

// check if the XML file is writable and then save data
if(is_writable($xmlPath)) {
	@file_put_contents($xmlPath, $xmlData);
}
</pre>
<p>Hope this helps. Thanks for reading.</p>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=585&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/php-read-write-xml-with-simplexml/' rel='bookmark' title='Permanent Link: PHP : Read Write Xml with SimpleXML'>PHP : Read Write Xml with SimpleXML</a></li>
<li><a href='http://blog.chapagain.com.np/php-read-write-xml-with-domdocument/' rel='bookmark' title='Permanent Link: PHP : Read Write Xml with DOMDocument'>PHP : Read Write Xml with DOMDocument</a></li>
<li><a href='http://blog.chapagain.com.np/magento-read-config-xml-nodes/' rel='bookmark' title='Permanent Link: Magento: Read config XML nodes'>Magento: Read config XML nodes</a></li>
<li><a href='http://blog.chapagain.com.np/php-read-write-csv/' rel='bookmark' title='Permanent Link: PHP: Read Write CSV'>PHP: Read Write CSV</a></li>
<li><a href='http://blog.chapagain.com.np/magento-helper-data-not-found-error/' rel='bookmark' title='Permanent Link: Magento: Helper Data not found error'>Magento: Helper Data not found error</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/magento-read-write-xml/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PHP : Read Write Xml with DOMDocument</title>
		<link>http://blog.chapagain.com.np/php-read-write-xml-with-domdocument/</link>
		<comments>http://blog.chapagain.com.np/php-read-write-xml-with-domdocument/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 06:12:12 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[dom]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=230</guid>
		<description><![CDATA[In this article, I will be showing you how to create and read xml document with php’s DOMDocument. The DOM extension allows you to operate on XML documents through the DOM API with PHP 5. Below is the code to create XML file. I have named the output file ‘example.xml’. For better understanding, I have [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/php-read-write-xml-with-simplexml/' rel='bookmark' title='Permanent Link: PHP : Read Write Xml with SimpleXML'>PHP : Read Write Xml with SimpleXML</a></li>
<li><a href='http://blog.chapagain.com.np/magento-read-write-xml/' rel='bookmark' title='Permanent Link: Magento: Read Write XML'>Magento: Read Write XML</a></li>
<li><a href='http://blog.chapagain.com.np/php-read-write-csv/' rel='bookmark' title='Permanent Link: PHP: Read Write CSV'>PHP: Read Write CSV</a></li>
<li><a href='http://blog.chapagain.com.np/magento-read-config-xml-nodes/' rel='bookmark' title='Permanent Link: Magento: Read config XML nodes'>Magento: Read config XML nodes</a></li>
<li><a href='http://blog.chapagain.com.np/javascript-add-remove-html-elements/' rel='bookmark' title='Permanent Link: Javascript: Add Remove HTML elements'>Javascript: Add Remove HTML elements</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In this article, I will be showing you how to create and read xml document with php’s DOMDocument.</p>
<blockquote><p>The DOM extension allows you to operate on XML documents through the DOM    API with PHP 5.</p></blockquote>
<p>Below is the code to create XML file. I have named the output file ‘example.xml’. For better understanding, I have written comment for almost every line of code.</p>
<p><span id="more-230"></span></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

// Create a new DOMDocument object
$dom = new DomDocument(&quot;1.0&quot;, &quot;ISO-8859-1&quot;);

// optionally the following can be done
// $dom-&gt;version  = &quot;1.0&quot;;
// $dom-&gt;encoding = &quot;ISO-8859-1&quot;;

// Create new element node 'mobiles'
$mobiles = $dom-&gt;createElement('mobiles');

// add $mobiles to the main dom
$dom-&gt;appendChild($mobiles);

// Suppose we have the following array of data
$items = array(array('name'=&gt;'samsung','price'=&gt;'21000'),
array('name'=&gt;'sony','price'=&gt;'25000'));

foreach($items as $item) {
// Create new element node 'brand'
$brand = $dom-&gt;createElement('brand');

// Create new element node 'name' with the node value
$name = $dom-&gt;createElement('name',$item['name']);

// Create new element node 'price' with the node value
$price = $dom-&gt;createElement('price',$item['price']);

// add 'name' node to 'brand' node
$brand-&gt;appendChild($name);

// add 'price' node to 'brand' node
$brand-&gt;appendChild($price);

// add brand to mobile
$mobiles-&gt;appendChild($brand);
}

// add spaces, new lines and make the XML more readable format
$dom-&gt;formatOutput = true;

// SET HEADER TO OUTPUT DATA

header('HTTP/1.1 200 OK');
header(&quot;Pragma: no-cache&quot;);
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Content-type', 'text/xml');
header('Content-Disposition: attachment; filename=&quot;example_dom.xml&quot;');

// Dump the internal XML tree back into a string
echo $dom-&gt;saveXML();

?&gt;
</pre>
<p>The following xml file is created. The xml file is named example_dom.xml.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
&lt;mobiles&gt;
&lt;brand&gt;
&lt;name&gt;samsung&lt;/name&gt;
&lt;price&gt;21000&lt;/price&gt;
&lt;/brand&gt;
&lt;brand&gt;
&lt;name&gt;sony&lt;/name&gt;
&lt;price&gt;25000&lt;/price&gt;
&lt;/brand&gt;
&lt;/mobiles&gt;
</pre>
<p>Here is the code to read the xml file. I have mentioned two ways to read the xml file. The first one loads the xml file, converts the data into string and prints it.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

// Create a new DOMDocument object
$xmlDoc = new DOMDocument();

// Load XML from a file
$xmlDoc-&gt;load(&quot;example_dom.xml&quot;);

// Dump the internal XML tree back into a string
echo $xmlDoc-&gt;saveXML();

?&gt;
</pre>
<p>The second way is to loop through the xml content and print. It’s more specific.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

// Create a new DOMDocument object
$xmlDoc = new DOMDocument();

// Load XML from a file
$xmlDoc-&gt;load(&quot;example_dom.xml&quot;);

// Search for all elements with tag name 'brand'
$brands = $xmlDoc-&gt;getElementsByTagName('brand');

// loop through brands and print brand name and price
foreach ($brands AS $key =&gt; $brand) {

// search for element 'name'
$name = $xmlDoc-&gt;getElementsByTagName('name');

// search for element 'price'
$price = $xmlDoc-&gt;getElementsByTagName('price');

// print node value for name and price
echo $name-&gt;item($key)-&gt;nodeValue . &quot; = &quot; . $price-&gt;item($key)-&gt;nodeValue . &quot;&lt;br /&gt;&quot;;
}
?&gt;
</pre>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=230&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/php-read-write-xml-with-simplexml/' rel='bookmark' title='Permanent Link: PHP : Read Write Xml with SimpleXML'>PHP : Read Write Xml with SimpleXML</a></li>
<li><a href='http://blog.chapagain.com.np/magento-read-write-xml/' rel='bookmark' title='Permanent Link: Magento: Read Write XML'>Magento: Read Write XML</a></li>
<li><a href='http://blog.chapagain.com.np/php-read-write-csv/' rel='bookmark' title='Permanent Link: PHP: Read Write CSV'>PHP: Read Write CSV</a></li>
<li><a href='http://blog.chapagain.com.np/magento-read-config-xml-nodes/' rel='bookmark' title='Permanent Link: Magento: Read config XML nodes'>Magento: Read config XML nodes</a></li>
<li><a href='http://blog.chapagain.com.np/javascript-add-remove-html-elements/' rel='bookmark' title='Permanent Link: Javascript: Add Remove HTML elements'>Javascript: Add Remove HTML elements</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/php-read-write-xml-with-domdocument/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP : Read Write Xml with SimpleXML</title>
		<link>http://blog.chapagain.com.np/php-read-write-xml-with-simplexml/</link>
		<comments>http://blog.chapagain.com.np/php-read-write-xml-with-simplexml/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 21:33:41 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[simplexml]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=225</guid>
		<description><![CDATA[In this article, I will be showing you how to create and read xml document with php&#8217;s SimpleXML extension. The SimpleXML extension provides a very simple and easily usable toolset to convert XML to an object that can be processed with normal property selectors and array iterators. Below is the code to create XML file. [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/php-read-write-xml-with-domdocument/' rel='bookmark' title='Permanent Link: PHP : Read Write Xml with DOMDocument'>PHP : Read Write Xml with DOMDocument</a></li>
<li><a href='http://blog.chapagain.com.np/php-read-write-csv/' rel='bookmark' title='Permanent Link: PHP: Read Write CSV'>PHP: Read Write CSV</a></li>
<li><a href='http://blog.chapagain.com.np/magento-read-write-xml/' rel='bookmark' title='Permanent Link: Magento: Read Write XML'>Magento: Read Write XML</a></li>
<li><a href='http://blog.chapagain.com.np/magento-collection-functions/' rel='bookmark' title='Permanent Link: Magento: Very Useful Collection Functions'>Magento: Very Useful Collection Functions</a></li>
<li><a href='http://blog.chapagain.com.np/magento-get-all-shopping-cart-items-and-totals/' rel='bookmark' title='Permanent Link: Magento: Get all shopping cart items and totals'>Magento: Get all shopping cart items and totals</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In this article, I will be showing you how to create and read xml document with php&#8217;s SimpleXML extension.</p>
<blockquote><p>The SimpleXML extension provides a very simple and easily usable    toolset to convert XML to an object that can be processed with    normal property selectors and array iterators.</p></blockquote>
<p><span id="more-221"></span></p>
<p>Below is the code to create XML file. I have named the output file &#8216;example.xml&#8217;. For better understanding, I have written comment for almost every line of code.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

// GENERATING XML NODE

// Create new SimpleXMLElement object
$itemsXml = new SimpleXMLElement(&quot;&lt;items&gt;&lt;/items&gt;&quot;);

// Add child element the SimpleXML element
$itemXml = $itemsXml-&gt;addChild('item');

// Add attribute to the SimpleXML element
$itemXml-&gt;addAttribute('id', 1);
$itemXml-&gt;addAttribute('type', 'simple');

$mobileXml = $itemXml-&gt;addChild('Mobiles');

// Suppose we have the following array of data
$items = array(array('name'=&gt;'nokia','weight'=&gt;'2'),
                array('name'=&gt;'samsung','weight'=&gt;'5'),
                array('name'=&gt;'sony','weight'=&gt;'3'));

foreach ($items as $item)
{
// XML PART
// Please look carefully on the variable names. They are important for using addChild method.
$brandXml = $mobileXml-&gt;addChild('Brand');
$nameXml = $brandXml-&gt;addChild('Name',$item['name']);
$weightXml = $brandXml-&gt;addChild('Weight',$item['weight']);
}

// FOR PROPER FORMATTING XML

// Create a new DOMDocument object
$doc = new DOMDocument('1.0');

// add spaces, new lines and make the XML more readable format
$doc-&gt;formatOutput = true;

// Get a DOMElement object from a SimpleXMLElement object
$domnode = dom_import_simplexml($itemsXml);

$domnode-&gt;preserveWhiteSpace = false;

// Import node into current document
$domnode = $doc-&gt;importNode($domnode, true);

// Add new child at the end of the children
$domnode = $doc-&gt;appendChild($domnode);

// Dump the internal XML tree back into a string
$saveXml = $doc-&gt;saveXML();

// SET HEADER TO OUTPUT DATA

header('HTTP/1.1 200 OK');
header(&quot;Pragma: no-cache&quot;);
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Content-type', 'text/xml');
header('Content-Disposition: attachment; filename=&quot;example.xml&quot;');

echo $saveXml;

?&gt;
</pre>
<p>The following xml file is created. The xml file is named example.xml.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;items&gt;
  &lt;item id=&quot;1&quot; type=&quot;simple&quot;&gt;
    &lt;Mobiles&gt;
      &lt;Brand&gt;
        &lt;Name&gt;nokia&lt;/Name&gt;
        &lt;Weight&gt;2&lt;/Weight&gt;
      &lt;/Brand&gt;
      &lt;Brand&gt;
        &lt;Name&gt;samsung&lt;/Name&gt;
        &lt;Weight&gt;5&lt;/Weight&gt;
      &lt;/Brand&gt;
      &lt;Brand&gt;
        &lt;Name&gt;sony&lt;/Name&gt;
        &lt;Weight&gt;3&lt;/Weight&gt;
      &lt;/Brand&gt;
    &lt;/Mobiles&gt;
  &lt;/item&gt;
&lt;/items&gt;
</pre>
<p>Here is the code to read the xml file.<br />
I have mentioned two ways to read the xml file. The first one loads the xml file, converts the data into string and prints it.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

// Get SimpleXMLElement object from an XML document
$xml = simplexml_load_file(&quot;example.xml&quot;);

// Get XML string from a SimpleXML element
// When you select &quot;View source&quot; in the browser window, you will see the objects and elements
echo $xml-&gt;asXML();

?&gt;
</pre>
<p>The second way is to loop through the xml content and print. It&#8217;s more specific.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

// Get SimpleXMLElement object from an XML document
$xml = simplexml_load_file(&quot;example.xml&quot;);

// Get the name of a SimpleXML element
echo &quot;&lt;p&gt;&lt;b&gt;Root Element:&lt;/b&gt; &lt;br/&gt;&quot;;
echo $xml-&gt;getName();
echo &quot;&lt;/p&gt;&quot;;

// get the attribute of 'item' element
// Get SimpleXML element's attributes
$attribute = $xml-&gt;item-&gt;attributes();

// $attribute is an object
// looping through the object and printing the attribute name and value
echo &quot;&lt;p&gt;&lt;b&gt;Attributes:&lt;/b&gt; (of element 'item')&lt;br/&gt;&quot;;
foreach($attribute as $key =&gt; $value) {
	echo $key . &quot; = &quot; . $value . &quot;&lt;br/&gt;&quot;;
}
echo &quot;&lt;/p&gt;&quot;;

// Get the children of a specified node
$children = $xml-&gt;children();
// echo &quot;&lt;pre&gt;&quot;; print_r($children);

foreach($children as $child) {
	// get mobiles brands
	$mobiles = $child-&gt;Mobiles-&gt;Brand;

	// print brand name
	echo &quot;&lt;p&gt;&lt;b&gt;Brands:&lt;/b&gt;&lt;br/&gt;&quot;;
	foreach($mobiles as $key =&gt; $value) {
		echo $value-&gt;Name . &quot;&lt;br/&gt;&quot;;
	}
	echo &quot;&lt;/p&gt;&quot;;
}

?&gt;
</pre>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=221&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/php-read-write-xml-with-domdocument/' rel='bookmark' title='Permanent Link: PHP : Read Write Xml with DOMDocument'>PHP : Read Write Xml with DOMDocument</a></li>
<li><a href='http://blog.chapagain.com.np/php-read-write-csv/' rel='bookmark' title='Permanent Link: PHP: Read Write CSV'>PHP: Read Write CSV</a></li>
<li><a href='http://blog.chapagain.com.np/magento-read-write-xml/' rel='bookmark' title='Permanent Link: Magento: Read Write XML'>Magento: Read Write XML</a></li>
<li><a href='http://blog.chapagain.com.np/magento-collection-functions/' rel='bookmark' title='Permanent Link: Magento: Very Useful Collection Functions'>Magento: Very Useful Collection Functions</a></li>
<li><a href='http://blog.chapagain.com.np/magento-get-all-shopping-cart-items-and-totals/' rel='bookmark' title='Permanent Link: Magento: Get all shopping cart items and totals'>Magento: Get all shopping cart items and totals</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/php-read-write-xml-with-simplexml/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>An introduction to RSS</title>
		<link>http://blog.chapagain.com.np/an-introduction-to-rss/</link>
		<comments>http://blog.chapagain.com.np/an-introduction-to-rss/#comments</comments>
		<pubDate>Tue, 06 May 2008 23:36:11 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[XML]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[syndication]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=58</guid>
		<description><![CDATA[RSS stands for Really Simple Syndication. RSS was designed to show selected data. Without RSS, users will have to check your site daily to check for new updates. This may be too time-consuming for many users. With an RSS feed (RSS is often called a News Feed or RSS Feed) they can check your site [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/introduction-of-facebook-connect/' rel='bookmark' title='Permanent Link: Introduction to facebook connect'>Introduction to facebook connect</a></li>
<li><a href='http://blog.chapagain.com.np/disqus-solution-to-error-closing-tag-mismatch-in-rss-feed/' rel='bookmark' title='Permanent Link: Disqus: Solution to Error &#8216;Closing Tag Mismatch&#8217; in RSS Feed'>Disqus: Solution to Error &#8216;Closing Tag Mismatch&#8217; in RSS Feed</a></li>
<li><a href='http://blog.chapagain.com.np/jquery-grey-out-background-and-preview-image-as-popup/' rel='bookmark' title='Permanent Link: jQuery: Grey out background and preview image as popup'>jQuery: Grey out background and preview image as popup</a></li>
<li><a href='http://blog.chapagain.com.np/an-introduction-to-pear/' rel='bookmark' title='Permanent Link: An Introduction to PEAR'>An Introduction to PEAR</a></li>
<li><a href='http://blog.chapagain.com.np/an-introduction-to-smarty-template-engine/' rel='bookmark' title='Permanent Link: An Introduction to Smarty Template Engine'>An Introduction to Smarty Template Engine</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="text-align: justify;">RSS stands for <strong>R</strong>eally <strong>S</strong>imple <strong>S</strong>yndication.</p>
<p><strong>RSS was designed to show selected data. </strong>Without RSS, users will have to check your site daily to check for new updates. This may be too time-consuming for many users. With an RSS feed (RSS is often called a News Feed or RSS Feed) they can check your site faster using an RSS aggregator (a site or program that gathers and sorts out several RSS feeds).<span id="more-58"></span></p>
<p class="MsoNormal" style="text-align: justify;">RSS is a protocol, an application of XML that provides an open method of syndicating and aggregating Web content. Using RSS files, you can create a data feed that supplies headlines, links, and article summaries from your Web site. Users can have constantly updated content from web sites delivered to them via a news aggregator, a piece of software specifically tailored to receive these types of feeds.</p>
<p>The main benefits of creating an RSS feeds include;</p>
<ul type="disc">
<li class="MsoNormal">RSS is an excellent and      cost-effective way of <strong>driving traffic</strong> to, and <strong>increasing brand      awareness</strong> of, any website that publishes content (e.g news, jobs,      events) regularly. Once a publisher produces an RSS file, they are      enabling others to syndicate their headlines, without any further work on      their part.</li>
<li class="MsoNormal">RSS is the <strong>dominant format</strong> for distributing headline content on the Web.</li>
<li class="MsoNormal">RSS allows <strong>easy sharing</strong> of data between sites. Webmasters can use an RSS file to easily      incorporate third party content into their own site.</li>
<li class="MsoNormal">Content from RSS feeds can be      <strong>easily repurposed </strong>allowing, for example, cross searching of a      number of different feeds at once.</li>
<li class="MsoNormal">RSS content can be added to <strong>personal      desktop news reading applications</strong> like Feedreader or AmphetaDesk.<span style="font-size: 12pt; font-weight: normal;"> </span></li>
</ul>
<p class="MsoNormal">Thank You.</p>
<p class="MsoNormal"><em><span style="text-decoration: underline;">Source:</span></em></p>
<p class="MsoNormal"><a href="http://www.w3schools.com/rss/rss_intro.asp" rel="nofollow" ><strong>http://www.w3schools.com/rss/rss_intro.asp</strong></a><span> </span></p>
<p class="MsoNormal"><a href="http://rssgov.com/rssworkshop.html" rel="nofollow" ><strong>http://rssgov.com/rssworkshop.html</strong></a></p>
<p class="MsoNormal"><a href="http://www.techxtra.ac.uk/rss_primer/" rel="nofollow" ><strong>http://www.techxtra.ac.uk/rss_primer/</strong></a></p>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=58&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/introduction-of-facebook-connect/' rel='bookmark' title='Permanent Link: Introduction to facebook connect'>Introduction to facebook connect</a></li>
<li><a href='http://blog.chapagain.com.np/disqus-solution-to-error-closing-tag-mismatch-in-rss-feed/' rel='bookmark' title='Permanent Link: Disqus: Solution to Error &#8216;Closing Tag Mismatch&#8217; in RSS Feed'>Disqus: Solution to Error &#8216;Closing Tag Mismatch&#8217; in RSS Feed</a></li>
<li><a href='http://blog.chapagain.com.np/jquery-grey-out-background-and-preview-image-as-popup/' rel='bookmark' title='Permanent Link: jQuery: Grey out background and preview image as popup'>jQuery: Grey out background and preview image as popup</a></li>
<li><a href='http://blog.chapagain.com.np/an-introduction-to-pear/' rel='bookmark' title='Permanent Link: An Introduction to PEAR'>An Introduction to PEAR</a></li>
<li><a href='http://blog.chapagain.com.np/an-introduction-to-smarty-template-engine/' rel='bookmark' title='Permanent Link: An Introduction to Smarty Template Engine'>An Introduction to Smarty Template Engine</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/an-introduction-to-rss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
