8000 [DomCrawler] Added node name getter by fejese · Pull Request #4039 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

< 8000 bdi class="js-issue-title markdown-title">[DomCrawler] Added node name getter #4039

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

Merged
merged 1 commit into from
Aug 16, 2014
Merged
Changes from all commits
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
9 changes: 9 additions & 0 deletions components/dom_crawler.rst
8000
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ Get all the child or parent nodes::
Accessing Node Values
~~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 2.6
The :method:`Symfony\\Component\\DomCrawler\\Crawler::nodeName`
method was introduced in Symfony 2.6.

Access the node name (HTML tag name) of the first node of the current selection (eg. "p" or "div")::

// will return the node name (HTML tag name) of the first child element under <body>
$tag = $crawler->filterXPath('//body/*')->nodeName();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a comment right above this that says what it returns. I actually wasn't 100% sure what "node name" was. I assumed correctly that it was the element name (e.g. body) but I wasn't sure!

// will return "body"
$tag = $crawler->filterXPath('//body/*')->nodeName();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to clarify if it's not 100% clear. However your example is not correct. The filter returns all children of body so it will return the HTML tag name of the first element under body.

To clear the confusion, how about this:

Access the node name (HTML tag name) of the first node of the current selection (eg. "p" or "div"):

// will return the node name (HTML tag name) of the first child element under <body>
$tag = $crawler->filterXPath('//body/*')->nodeName();


Access the value of the first node of the current selection::

$message = $crawler->filterXPath('//body/p')->text();
Expand Down
0