du6jws6975 2016-03-23 19:02
浏览 108

使用Symfony进行XML解析

I have a XML file in a url. I want to parse data from the xml and to hydrate my entity.

I've code that (crawler) but this does not work (empty response).

public function getUsersAction(Request $request)
{
    $crawler = new Crawler();
    $crawler->addXmlContent(
        file_get_contents(
            'http://localhost/myproject/web/feed-users.xml'
        )
    );

    json_encode($crawler);

    return new JsonResponse(
        array(
            'crawler' => $crawler
        )
    );
}

Thanks

  • 写回答

1条回答 默认 最新

  • dtftao7249656 2016-03-23 21:36
    关注

    You need to parse your $crawler after you injected xml feed in it.

    use Symfony\Component\CssSelector\CssSelector;
    
    public function getUsersAction(Request $request)
    {
    
        CssSelector::disableHtmlExtension();
        $crawler = new Crawler(file_get_contents('http://localhost/myproject/web/feed-users.xml'));
    
        $value = $crawler->filter('.someCssSelectorForInstance');
    }
    

    You can dump($crawler) after injecting the xml feed and you'll see that your crawler is ready to go

    评论

报告相同问题?

悬赏问题

  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式