Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
weaverryan merged 1 commit intosymfony:masterfromfejese:node-name-getter
Aug 16, 2014
Merged
Changes fromall 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 deletionscomponents/dom_crawler.rst
View file
Open in desktop
Original file line numberDiff line numberDiff 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
ContributorAuthor

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 ofbody so it will return the HTML tag name of the first element underbody.

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

[8]ページ先頭

©2009-2025 Movatter.jp