Oh, I ran diagnostics. Why do you assume I didn't?
For the same reason I would assume anything else: You didn't say you had done so, and you didn't post any results that suggested you did.
We can't read your mind.
We can't see your screen.
All we know about what you did is what you tell us.
All we can see about your code is what you post.
Here is the start of the tree displayed by DOMTreeView:
V #document
........html
......V HTML
..........> HEAD
..........> BODY
Does this show that the document node has two children?
I don't know, I haven't used DOMTreeView. Google doesn't turn up much that's useful in explaining it, either.
If you don't know how to use it, or can't interpret its output, then you should probably invest a little time and write your own diagnostics. It shouldn't be that hard. DOMNode has methods that tell you whether a node has children, and what the first child node is. Having the first child node, you can get the next sibling node, too.
Again, I refer you to this link:
http://www.w3schools.com/htmldom/default.asp
The diagram there clearly shows one child node of the document node. That node (called the root element, with name html) has two child nodes, head and body.
The code I use to get the starting node is:
Code:
[[self mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://en.wikipedia.org/wiki/Main_Page"]]];
node = [[self mainFrame] DOMDocument];
I used Safari to get that page. From Safari's Develop menu I then chose Show Web Inspector. This clearly shows an HTML root element with two children: head and body.
All the evidence I find, plus my experience using JavaScript to access DOM nodes, strongly suggests there is one child node of the document, which is the root HTML element. The root element has two children: head and body. If that doesn't match your expectation, then you might want to confirm your expectation is correct by trying to obtain evidence that supports it. If the evidence suggests a different structure, then you might need to adjust your expectation.