How do I load an XML file using Crawler?

11,538

Have you tried this?

$document = new \DOMDocument();
$document->loadXml(file_get_contents('my_file.xml'));

$crawler = new Crawler();
$crawler->addDocument($document);

or this?

$crawler = new Crawler();
$crawler->addXmlContent(file_get_contents('my_file.xml'));

Read more on DomCrawler component and how to load content into it: http://symfony.com/doc/current/components/dom_crawler.html#adding-the-content

Share:
11,538
skonsoft
Author by

skonsoft

Symfony Consultant My Own website: Skonsoft INVENT

Updated on June 22, 2022

Comments

  • skonsoft
    skonsoft almost 2 years

    I need to load xml files and store them into a database. I'm using Symfony 2.1 as a framework and this framweork comes with a great tool - the crawler. It makes using XPATH easy.

    How do I load XML files using this crawler?

    Have you any a good tutorial showing how to do that?