Manoj
Manoj

Reputation: 1696

parse XML with all its attributes - Laravel orchestra Parser

I want to parse all XML attributes.

I wasn't able to access (NAME & TYPE) from :

 <productlist name="MRF">

 <product type="BAT">

Can someone help me parse these attributes with the rest of the data?

$xml = XmlParser::load(url(myxmlfile.xml));

$xmlProduct = $xml->parse([

   'product'   => [
      'uses'=>'product[name,price,type]'
   ],

]);

My XML Example

<productlist name="MRF">
     <product type="BAT">
        <name>
           <![CDATA[ mrf genius limited edition ]]>
        </name>
        <price>
           <![CDATA[ 11999 ]]>
        </price>
        <type>
           <![CDATA[ english willow ]]>
        </type>
     </product>
 </productlist>

Upvotes: 0

Views: 1811

Answers (1)

Manoj
Manoj

Reputation: 1696

These are the links to the documentation

https://packagist.org/packages/orchestra/parser

https://github.com/orchestral/parser

This is what I did to solve my problem :

use Orchestra\Parser\Xml\Facade as XmlParser;

$xml = XmlParser::load(url(myxmlfile.xml));
$xmlProduct = $xml->parse([ 

     'name' => ['uses' => '::name'],
     'Type' => ['uses' => 'product::type'],
     'price' => ['uses' => 'product.price'],
     'bat_type' => ['uses' => 'product.type'],
); 

This is how I was able to parse my xml.

Upvotes: 0

Related Questions