Home » Magento, XML17 February 2010

Magento: Read Write XML

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 XML data. I have kept the XML file in the root directory of Magento installation. The XML file is named test.xml. At first, the XML file is loaded and then it’s node are read with getNode function. Then, I have printed the result.

You can add node with the setNode function. Here, I have set a node inside the node ‘modules’. The name of my new node is ‘mukesh’ and it’s value is ‘chapagain’.

Hope this helps. Thanks.


Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Pingback: Timon takes on Nichols at 9 a.m. Friday – Metro WNY Blogs, Buffalo … | Buffalo Bills NFL Announcer()

  • Pingback: Magento: Read Write XML | Mukesh Chapagain's Blog | Magento News()

  • I have been looking help for my Magento related queries, this was one of my query, as I ma new to Magento. I have been learning it around in internet. I think I will visit your website daily to get good knowledge on Magento.
    magento themes

  • Mariawi9232

    Do you have an idea how can you add attributes into those created XML elements?

  • jaikanth123

    This query was really helpfull to me because i was not knowing to configure XML configuration.

  • Nice tutor.Your way of presentation is too good.I like the information you have managed & compile.Its really a unique & real information.I would like to read your more updates in future too.Keep in touch with us.

  • Nice and smart written article.I really liked it a lot.Thanks a lot for sharing such article with us.Keep sharing.

  • fsc

    I am writing a module which needs to add/remove cronjobs dynamically. Is it ok to change the config.xml file dynamically or should it be avoided?

  • Archana

    I am getting error Fatal error: Call to a member function setNode() on a non-object in C:wampwwwxxxxxxlibVarienSimplexmlConfig.php on line 550

  • Vivek Shingala

    Hi Mukesh

    How can we do this in Magento 2?