1
$\begingroup$

In my understanding, given the same input that is an XML or an HTML document,

Here and there you will get a source that saying the result of parsing HTML is DOM (e.g. The HTML Parser Book), which I think not completely correct (though useful for those who don't care about the syntax tree). There are libraries distinguishing the two concepts, like hast-util-to-dom. So clearly the two are different.

But all of those links don't explain the differences between a DOM and a syntax tree.

asked Dec 1, 2024 at 9:26
$\endgroup$
3
  • $\begingroup$ This question seems to come down to a question about what is in the Mozilla DOM data structure. I'm not sure that's on-topic here, as it sounds to me like a question about a particular implementation or a particular piece of software. Questions about concepts are OK, but generally not questions about implementations. See our help center and cs.meta.stackexchange.com/q/2908/755. Others might have a different view, or maybe there is something I'm missing. $\endgroup$ Commented Dec 2, 2024 at 0:27
  • $\begingroup$ Do you mean that different browsers have different models? While MDN is indeed managed by Mozilla, it is the source for devs of Non-Firefox browsers as well. It just re-documents the WHATWG specification on DOM $\endgroup$ Commented Dec 2, 2024 at 4:20
  • $\begingroup$ Thanks for clarifying that, I was unaware. Given that, it seems to be asking about an implementation matter -- the behavior of the WHATWG DOMParser API -- as opposed to about concepts, so I'm not sure whether folks will consider it appropriate here. I will leave it up to others to judge. $\endgroup$ Commented Dec 2, 2024 at 5:27

1 Answer 1

1
$\begingroup$

DOM is not a syntax tree, it is a standard API that provides standard methods to work with the tree that represents the page contents.

The methods can not only read the tree, they can also modify it, causing the page contents to change.

answered Dec 2, 2024 at 9:56
$\endgroup$
6
  • $\begingroup$ DOM is an object model. Isn't that object model isn't an API? And I can surely have a lib that provides API to manipulate the syntax tree? $\endgroup$ Commented Dec 2, 2024 at 12:36
  • $\begingroup$ An object model is an API, as far as I know. $\endgroup$ Commented Dec 2, 2024 at 13:28
  • $\begingroup$ In that case, why isn't the syntax tree an object model as well? You can say it's a tree, but that tree must be represented as an object, thus we have an object model of the tree. DOM is exactly the same $\endgroup$ Commented Dec 3, 2024 at 4:12
  • $\begingroup$ Well, if you're working in an object-oriented language, and your syntax tree is represented in terms of objects in your language, then that will give you an object model for your syntax tree. Note there are a few assumptions there. But the methods in that model can be anything and do anything. DOM is a standard object model that is provided to you. It is not a library, it is a specification of what the methods in that library must be called and what they must do. $\endgroup$ Commented Dec 3, 2024 at 10:49
  • $\begingroup$ You say that DOM is not a syntax tree, but this comment says it is. What do you think about it? $\endgroup$ Commented Dec 5, 2024 at 3:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.