4

I have read about the XML DOM and the HTML DOM, but I don't see a big difference. In the w3schools there are two articles, XML DOM and HTML DOM, describing the two DOM's, but I think they are a lot like. I have also read the post on stackoverflow, but it's more about using the methods/properties between the DOMS, rather than the difference. I also couldn't find anything at Google about it.

I know that the DOM is a way of representing the HTML and XML document, and is illustrated by a tree. I also know what the DOM looks like for an HTML document and an XML document, and how to manipulate them.

So what are the differences?

Saeed Hassanvand
  • 931
  • 1
  • 14
  • 31
barto90
  • 679
  • 1
  • 9
  • 27
  • XML is more fickle. No but really, XML is much more strict in its syntax. It can also be used for basically anything. People create their own XML schemas all the time to store data. – thatidiotguy Nov 13 '12 at 19:28
  • 1
    HTML DOM is defined by the W3C HTML specifications/drafts which define the IDL (e.g. allowed DOM access methods) as well as allowed elements, relationships, white-space rules, etc (it's a specialization / "schema" of SGML). A *plain* XML DOM is just data without any intrinsic structure without an applied DTD/XSD; also the XML DOM has a slightly different IDL and additional concepts like namespaces. –  Nov 13 '12 at 19:28
  • 3
    Try to avoid w3schools as a "trusted" source: http://w3fools.com/ – Martin Lyne Nov 13 '12 at 19:31
  • These days (2022) w3fools says "Today, W3Schools has largely resolved these issues and addressed the majority of the undersigned developers' concerns. " – Michael Kay Feb 24 '22 at 16:34

2 Answers2

7

The main difference is that the HTML DOM knows about HTML: it knows, for example, that a table contains a table body which contains table rows, and it will ensure that when you add and remove nodes to the tree that this structure is correctly maintained.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
1

Mostly the difference is that character case will be preserved in XML DOM APIs but not necessarily in HTML DOM APIs.

For an example of this, see JavaScript: detect parser used, XML or SGML

Community
  • 1
  • 1
Alohci
  • 78,296
  • 16
  • 112
  • 156