Rubberduck1337106092
Rubberduck1337106092

Reputation: 1344

Parsing XML in laravel: get @attributes value

I have a XML file with account information I need to be loaded in my user's table in my database.

I found this package for Laravel for XML parsing:

https://github.com/orchestral/parser

I came thus far that I can load my XML but now I am stuck. Here's the code:

$xml = XmlParser::load(url('/xml/DEBTORS.xml'));
    dd($xml);
    $user = $xml->parse([
       'Name' => ['uses','Accounts.Account.Name'],
    ]);

$user Name returns NULL

enter image description here

Part of the XML for example:

<Account code="1004" status="A" type="C">
 <Name>example name here</Name>
 <Phone>emaple phone here</Phone>

For example I want to reach Account Code in @attributes and assign that to ID.

Any help is appreciated.

Upvotes: 1

Views: 5489

Answers (1)

Abhishek
Abhishek

Reputation: 3967

$xml = XmlParser::load(url('/xml/DEBTORS.xml'));
$user = $xml->parse([
   'Name' => ['uses','Accounts.Account.Name'],
   'Id'   => ['uses','Accounts.Account::code']
]);

From doc

Upvotes: 1

Related Questions