Reputation: 260
I want to parse a list of packages that contains a list of pictures. However I am able to get the first element but not the full array. The parser I'm using is Laravel's Orchestra.
The XML to be unpacked:
<Packages>
<Package>
<Pictures>
<P>20205520574081..jpg</P>
<P>20205520574701.jpg</P>
<P>20205520575172.jpg</P>
<P>20205520575483.jpg</P>
<P>20205520575955.jpg</P>
<P>20205520576426.jpg</P>
<P>20205520576897.jpg</P>
<P>20205520577368.jpg</P>
<P>20205520577989.jpg</P>
</Pictures>
</Package>
<Package>
<Pictures>
<P>20205520574081..jpg</P>
<P>20205520574701.jpg</P>
<P>20205520575172.jpg</P>
<P>20205520575483.jpg</P>
<P>20205520575955.jpg</P>
<P>20205520576426.jpg</P>
<P>20205520576897.jpg</P>
<P>20205520577368.jpg</P>
<P>20205520577989.jpg</P>
</Pictures>
</Package>
My extraction code:
$OfferSummary = $xml->parse([
'Images' => ['uses' => 'Packages.Package.Picture[P]'],
]);
My result:
["Images"]=>
array(1) {
[0]=>
array(1) {
["P"]=>
string(19) "20205520574081..jpg"
}
....
}
Please note that only the first element of the pictures tag is returned, and I need the entire array of elements.
Thanks!
Upvotes: 0
Views: 298
Reputation: 11
I had a similar problem. My XML had a list in which every sub-node had a name attribute. In my case I found the answer here: https://github.com/orchestral/parser/blob/master/tests/Feature/DocumentTest.php#L52
In my case the solution was:
$parser = $xml->parse([
'products' => ['uses' => 'products.product[attributes.attribute_group.value(::name=@)]'],
]);
Upvotes: 1