Skip to content

Commit 68fa18e

Browse files
jakzalweaverryan
authored andcommitted
Documented explicit namespace registration.
1 parent 47bc7dc commit 68fa18e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

components/dom_crawler.rst

+10-3
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ To remove a node the anonymous function must return false.
9797

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

102103
.. versionadded:: 2.4
103-
Auto discovery of namespaces was introduced in Symfony 2.4.
104+
Auto discovery and explicit registration of namespaces was introduced
105+
in Symfony 2.4.
104106

105107
Consider an XML below:
106108

@@ -136,13 +138,18 @@ and :method:`Symfony\\Component\\DomCrawler\\Crawler::filter`::
136138
changed with the
137139
:method:`Symfony\\Component\\DomCrawler\\Crawler::setDefaultNamespacePrefix`.
138140

141+
Namespaces can be explicitly registered with the
142+
:method:`Symfony\\Component\\DomCrawler\\Crawler::registerNamespace`::
143+
144+
$crawler->registerNamespace('m', 'http://search.yahoo.com/mrss/');
145+
$crawler = $crawler->filterXPath('//m:group//yt:aspectRatio');
146+
139147
.. caution::
140148

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

145-
146153
Node Traversing
147154
~~~~~~~~~~~~~~~
148155

0 commit comments

Comments
 (0)