Home » Magento, XML

Magento: Read config XML nodes

17 February 2010 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

email

php magento mukesh chapagain

Get New Post by Email
RSS Feed Subscribe RSS Feed
  • Gregc

    Looks like you need to add the default node in as well

    echo Mage::getConfig()->getNode(‘default/catalog/mypage’)->name;

    works

    Greg