Skip to content

[DomCrawler] Documented xml namespace autodiscovery #2979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[DomCrawler] Documented explicit namespace registration.
  • Loading branch information
jakzal committed Sep 22, 2013
commit f7a16c2255d540faa7ee93a31d9ab3f8e69b24d0
13 changes: 10 additions & 3 deletions components/dom_crawler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ To remove a node the anonymous function must return false.

Both :method:`Symfony\\Component\\DomCrawler\\Crawler::filterXPath` and
:method:`Symfony\\Component\\DomCrawler\\Crawler::filter` methods work with
XML namespaces, which are automatically registered.
XML namespaces, which can be either automatically discovered or registered
explicitly.

.. versionadded:: 2.4
Auto discovery of namespaces was introduced in Symfony 2.4.
Auto discovery and explicit registration of namespaces was introduced
in Symfony 2.4.

Consider an XML below:

Expand Down Expand Up @@ -136,13 +138,18 @@ and :method:`Symfony\\Component\\DomCrawler\\Crawler::filter`::
changed with the
:method:`Symfony\\Component\\DomCrawler\\Crawler::setDefaultNamespacePrefix`.

Namespaces can be explicitly registered with the
:method:`Symfony\\Component\\DomCrawler\\Crawler::registerNamespace`::

$crawler->registerNamespace('m', 'http://search.yahoo.com/mrss/');
$crawler = $crawler->filterXPath('//m:group//yt:aspectRatio');

.. caution::

To query an XML with a CSS selector, the HTML extension needs to be disabled with
:method:`Symfony\\Component\\CssSelector\\CssSelector::disableHtmlExtension`
to avoid converting the selector to lowercase.


Node Traversing
~~~~~~~~~~~~~~~

Expand Down