I am loading custom xml feed file myfeed.xml from third party server. This file is publically accessible. Not any authentication set.

 <valley street name="jackson">

       <name>Product 1</name>
       <description> Description 1</description>
            <name>Product 2</name>
       <description> Description 2</description>

       <name>Product 3</name>
       <description> Description 3</description>




How to read all item nodes from the valley? I need help to read this xml data magento 2 standard method way not php method or class.

I know how to create custom configuration file and process it but i want to check if any other method available to read the xml and process it.

Is there any native magento2 class that allows me to read custom xml?

Any help would be appreciated.


You can conver your XML to PHP Array using following code:

$xml = simplexml_load_string($xmlstring, "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode($xml);
$array = json_decode($json,TRUE);

May be this will help you.

NOTE: your XML format should be correct.

| improve this answer | |
  • 1
    I already know this way as well. i want to know is there any magento native class or library that allows me to do so? I want to manage backward compatibility as well. so prefer the magento based code – Jackson Wyss May 8 '19 at 6:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.