使用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

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