use*_*591 3 xml laravel laravel-5
我有这个我想要导入的XML:
<products>
<product product_id="62" title="Product Title" description="<p>desc</p>" price="40" brand="" weight="100" in_stock="Y"/>
<product product_id="63" title="Product Title" description="<p>desc</p>" price="40" brand="" weight="100" in_stock="Y"/>
</products>
Run Code Online (Sandbox Code Playgroud)
我正在使用Laravel 5和这个软件包:https://github.com/orchestral/parser
所以我正在运行这段代码:
$xml = XmlParser::load('https://www.url/feed.xml');
$product = $xml->parse([
'product_id' => ['uses' => 'product::product_id'],
'title' => ['uses' => 'product::title'],
'description' => ['uses' => 'product::description'],
]);
dd($product);
Run Code Online (Sandbox Code Playgroud)
但它只是在一个数组中返回一个产品,它甚至不是XML中的第一个或最后一个.所以我有点困惑.
有人有任何想法吗?
谢谢.
我最后做的是:
$xml = XmlParser::load('https://www.url/feed.xml');
$products = $xml->getContent();
foreach($products as $product) {
$item->title = $product['title'];
$item->save();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2040 次 |
最近记录: |