Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XML符号数据检索_Xml_Symfony - Fatal编程技术网

XML符号数据检索

XML符号数据检索,xml,symfony,Xml,Symfony,我有一个XML文件,其中保存了一些产品详细信息:ID、名称、价格 如何在表中显示这些行? 我应该使用教义吗?我应该把XML文件放在哪里?然后在公共场所安装资产 这是我的products.xml <products> <product> <id>2222</id> <manufacturer>AMINE</manufacturer> <name>*AMINE 123 185/65

我有一个XML文件,其中保存了一些产品详细信息:ID、名称、价格

如何在表中显示这些行? 我应该使用教义吗?我应该把XML文件放在哪里?然后在公共场所安装资产

这是我的products.xml

<products>
<product>
    <id>2222</id>
    <manufacturer>AMINE</manufacturer>
    <name>*AMINE    123    185/65 R15 88 T</name>
    <additional>AUSLAUF</additional>
    <price>74.24</price>
    <availability>4</availability>
    <product_image>http://media2.tyre24.de/images/tyre/330-R-w300-h300-br1.jpg</product_image>
</product>
<product>
    <id>3333</id>
    <manufacturer>AMINE</manufacturer>
    <name>*AMINE    456    185/65 R15 88 T</name>
    <additional>AUSLAUF</additional>
    <price>74.24</price>
    <availability>4</availability>
    <product_image>http://media2.tyre24.de/images/tyre/330-R-w300-h300-br1.jpg</product_image>
</product>
<product>
    <id>3333</id>
    <manufacturer>AMINE</manufacturer>
    <name>*AMINE    789    185/65 R15 88 T</name>
    <additional>AUSLAUF</additional>
    <price>74.24</price>
    <availability>4</availability>
    <product_image>http://media2.tyre24.de/images/tyre/330-R-w300-h300-br1.jpg</product_image>
</product>

2222
胺
*胺123 185/65 R15 88 T
奥斯拉夫
74.24
4.
http://media2.tyre24.de/images/tyre/330-R-w300-h300-br1.jpg
3333
胺
*胺456185/65R1588T
奥斯拉夫
74.24
4.
http://media2.tyre24.de/images/tyre/330-R-w300-h300-br1.jpg
3333
胺
*胺789 185/65 R15 88 T
奥斯拉夫
74.24
4.
http://media2.tyre24.de/images/tyre/330-R-w300-h300-br1.jpg
使用“simplexml加载文件($url);”功能。此函数将XML文件转换为SimpleXMLElement对象,然后输出对象的键和元素

在“json_decode(json_encode((array)$var_name),1)”之后,此函数将该对象转换为json对象。通过使用这个josn对象,我们可以做任何我们想做的事情

 public function functionNameAction(){
    // Write your code
    try {
        $simpleXMLElementObject = simplexml_load_file($file_url);
        $xml_josn_object = json_decode(json_encode((array)$simpleXMLElementObject),1);
    }catch (\Exception $e){
        // Handle the exception 
    }

    // Render your template and pass this $xml_josn_object into the template and do what ever you want in that template
}

仅供参考

我已经完成了这项工作,但我无法在小树枝页面中显示!!!,如何循环和显示这些元素?没有什么难以显示的。只需找出属性名并循环即可//在twig中,只需像{feed.LiftStatusMorning.LiftStatus%}{{lift.lift}}{%endfor%}那样编写{%forlift