Home » Magento, XML

Magento: Read config XML nodes

17 February 2010 736 views No Comment Popularity: 8% Share/Bookmark

Here, I will be showing you how you can read XML nodes from config.xml file of your module. It’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.

<default>
	<catalog>
		<mypage>
			<name>myname</name>
			<age>100</age>
			<address_one>earth</address_one>
		</mypage>
	</catalog>
</default>

Here is the code to read the node of the above XML file. Here, ‘catalog/mypage‘ is parent nodes path. It depends upon XML node layout.

// prints 'myname'
echo Mage::getConfig()->getNode('catalog/mypage')->name;

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

// prints 'earth'
echo Mage::getConfig()->getNode('catalog/mypage')->address_one;

Hope this helps and thanks for reading.

From Mukesh Chapagain's Blog | Post Magento: Read config XML nodes

Related posts:

  1. Magento: Read Write XML
  2. PHP : Read Write Xml with SimpleXML
  3. PHP : Read Write Xml with DOMDocument
  4. Magento: Access denied in admin of custom module
  5. Magento Error – Notice: Undefined index: 0 app/code/core/Mage/Core/Model/Mysql4/Config.php on line 92

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.