What is DOM Parser?

Reading about regular expression I saw a recurring term, DOM parser, and my doubts arose:

  1. What is DOM Parser?
  2. How does it work?
  3. every language has?
Author: Maniero, 2017-01-25

1 answers

Parser

Let's start with the parser. It is an algorithm that parses a text by identifying its parts ( tokens ) and checking that everything is constructed as determined by a specified grammar (probably in BNF). In this specific use it does the analysis of an XML document, HTML, etc. and generates a gift for the application to use.

It will do element-by-Element Analysis of the text and create the tree structure. This is explained a little better in a question about how a compiler works.

DOM

The Document Object Model is a large hierarchical object with several elements forming a tree.

It is very common to find the DOM associated with XML languages and similar. It is possible for some programming language compilers to generate a gift of the code for their own use, and even make it available for the application to use in time execution. C# does that, but today it has better solutions.

I don't like the name very much because it refers to doing the parsing of the DOM and in fact the DOM is the result it generates.

Every language has?

Since the DOM parser is a software with several function-specific components it is not what languages will have or not, it is a matter of having a library with that function available for that language. If the language handles XML, HTML or something like that it is pretty sure there's something ready in the standard language library. The quality and extent of each may vary.

If the "language" does not always have it is possible to use a third-party library.

Do not confuse the DOM with the text itself that generates this model. An HTML is not the DOM, but it is normal to have a direct relationship between them. You can manipulate the DOM without manipulating the HTML. Or XML, or JSON( less common), SVG, etc. JavaScript handles DOM, not HTML directly.

The parser delivers a partial or integral tree-like structure so that the Consumer Code can do what it wants. In general, the parser library allows you to easily access the members of the DOM and even manipulate it.

Some languages, such as JavaScript, by specific characteristic, can have access to the DOM directly, since the DOM ends up being incorporated into the code identifiers.

Is being created a formal specification of how it should work.

See more in what parse is, and how DOM parse works in HTML5.

 4
Author: Maniero, 2020-06-11 14:45:34