Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
[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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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(); | ||