Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7585599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:12:54+00:00 2026-05-30T19:12:54+00:00

So far I’m working on a HTML file like this <div name=node></div> <div></div> <div

  • 0

So far I’m working on a HTML file like this

<div name="node"></div>
<div></div>
<div name="node"></div>
<div></div>
<div name="node"></div>
<div></div>

I want to select the next node of every “div” which has its name equal to “node” and I try :

$dom = new DOMdocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);

$els = $xpath->query("//div[@name='node']");

$j = 0;

foreach($els as $el)
{
    if($el->next_sibling()) $j++;
}

echo $j;

But I just get an error

Fatal error: Call to undefined method DOMElement::next_sibling()

Can anybody tell me what’s wrong with my script please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:12:56+00:00Added an answer on May 30, 2026 at 7:12 pm

    The error is quite clear: there is no method DOMElement::next_sibling(). Read the documentation for DOMElement and it’s parent class DOMNode. You are thinking of the property DOMNode::nextSibling.

    However, nextSibling gets the next node, not the next element. (There is no DOM method or property that gets the next element. You need to keep using nextSibling and checking nodeType until you hit another element.) Your question says you want the next node but I think you may actually want the next element (the empty <div>). This is actually quite easy to do with XPath, so why don’t you do that instead?

    To get it immediately:

    $els = $xpath->query("//div[@name='node']/following-sibling::*[1]");
    

    To get it when you already have a <div name="node">:

    $nextelement = $xpath->query("following-sibling::*[1]", $currentdiv);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As far as I can tell this is perfectly valid batch-file code, just a
As far as I know this isn't possible. I would like to draw an
So far i got this code: function toplist() {$sql = SELECT * FROM list
Far as best practices are concerned, which is better: public void SomeMethod(string str) {
As far as I know, in gcc you can write something like: #define DBGPRINT(fmt...)
As far as I can tell, this is isn't possible, so I'm really just
so far, I have this: class Foo{ private $plugin_methods = array(); public function registerPlugin($caller,
So far i wrote a code to download a file from ftp server then
So far i have the following code, but it doesn't seem to be working,
As far as I see every time I make a change, for example the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.