使用Laravel包orchestral/parser导入XML时出现的问题
我有一个要导入的XML:使用Laravel包orchestral/parser导入XML时出现的问题,xml,laravel,laravel-5,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&
<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>
但它只是返回一个数组中的单个产品,它甚至不是XML中的第一个或最后一个。所以我有点困惑
有人有什么想法吗
谢谢。我最后做的是:
您可以在Laravel上尝试“simplexml\u load\u string()
当您使用此函数解析xml文件时,不需要在Laravel项目中包含其他插件
参考:
例如:
$test_strting="<posts>
<post>
<title>Title1</title>
</post>
<post>
<title>Title2</title>
</post>
</posts>";
$xml = simplexml_load_string($test_strting);
foreach ($xmltest->post as $key => $value)
{
$title = (string) $value->title;
echo("Title: ".$title);
}
$test\u strting=”
标题1
标题2
";
$xml=simplexml\u load\u字符串($test\u strting);
foreach($xmltest->post as$key=>$value)
{
$title=(字符串)$value->title;
echo(“标题:.$Title”);
}
dd($xml)返回什么?
$xml = XmlParser::load('https://www.url/feed.xml');
$products = $xml->getContent();
foreach($products as $product) {
$item->title = $product['title'];
$item->save();
}
$test_strting="<posts>
<post>
<title>Title1</title>
</post>
<post>
<title>Title2</title>
</post>
</posts>";
$xml = simplexml_load_string($test_strting);
foreach ($xmltest->post as $key => $value)
{
$title = (string) $value->title;
echo("Title: ".$title);
}