我有这个要导入的 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>
我正在使用 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);
但它只是返回数组中的单个产品,它甚至不是 XML 中的第一个或最后一个产品。所以我有点困惑。
有人有什么想法吗?
谢谢。
最佳答案
我最后做的是:
$xml = XmlParser::load('https://www.url/feed.xml');
$products = $xml->getContent();
foreach($products as $product) {
$item->title = $product['title'];
$item->save();
}
关于xml - 使用 Laravel Package orchestral/parser 导入 XML 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33944228/