2

I am generating XPaths server-side for use on the client-side, and I was puzzled as why only table paths (i.e. content in a td) couldn't be found in the DOM.

Turns out, modern browsers (at least Chrome and Firefox) insert a tbody tag around table rows upon document loading. See Why do browsers insert tbody element into table elements?

Apart from tbody, are there other DOM elements I should be aware of when calculating XPaths server-side?

Community
  • 1
  • 1
  • If you make sure your server side HTML is _actually_ valid, you don't have any problems. – Raynos Jan 19 '12 at 14:06
  • @Raynos False. Some elements have optional both start and end tags; your markup can be valid but the elements are still inserted. – duri Jan 19 '12 at 14:36
  • @duri your right, emitting `` is valid. I'll correct the statement to say "If you make sure your server side HTML is not ambigious then you won't have any problems" – Raynos Jan 19 '12 at 14:48

1 Answers1

3

In SGML/HTML4 terminology some other elements can be inferred, even the head and the body element can be inferred, and HTML5 continues that. So a document like http://home.arcor.de/martin.honnen/html/test2012011901.html is valid HTML5 although it does neither have head nor body element and any HTML5 parser is supposed to add them so the DOM tree looks like

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<h1>Test</h1>
<p>This is a test.</p>
</body>
</html>

I can't tell you all details about other elements, the above is only an example. Look for details in http://www.w3.org/TR/html5/syntax.html#optional-tags.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110