Home > Blockchain >  Relation between XML and HTML
Relation between XML and HTML

Time:10-27

I am a bit confused about something. I know that Typescript is a superset of JavaScript since you can put JavaScript into Typescript but not the other way around. Someone told me that there is a similar relation between HTML and XML. I can however not find anything concrete about this on the web. Is this true? And if so, what is the superset?

CodePudding user response:

HTML is a markup vocabulary: a set of concrete element and attribute definitions and other things such as predefined entities. SGML is a markup meta-language: a language to define the elements, attributes, and predefined entities of markup vocabularies, and was used to define HTML until version 4, though HTML introduced special commenting rules to prevent inline JavaScript and CSS to be rendered as content in older browsers back when those features were introduced. XML was created in 1996/1997 as a simplified SGML subset (by the original SGML creators while at W3C) for defining new markup vocabularies beyond HTML on the web, such as SVG and MathML (which have been since integrated into WHATWG's HTML 5.x as foreign content), but was much more successful outside the web.

The things left out from SGML to yield XML were mostly so-called markup minimization features: features that allow tag omission/inference and attribute short forms. An explicit goal of XML was to define generically parseable markup without any need for per-element or per-attribute parsing rules; that is, where markup declarations are optional and can be used for validation, but aren't required for parsing.

Because XML doesn't support SGML tag inference, attribute short forms and other things, XML can't be used to parse HTML. For example, the following HTML document requires element declarations telling a parser to infer missing html, head, and body tags, and that the img element mustn't have an end-element tag:

<title>The title</title>
<p>The body text</p>
<img src="..." alt="...">

Where the canonical fully-tagged markup for that document is

<html>
  <head>
    <title>The title</title>
  </head>
  <body>
    <p>The body text</p>
    <img src="..." alt="...">
  </body>
</html>

Note that WHATWG's HTML 5.x specification doesn't anymore normatively reference SGML but defines HTML parsing in a self-contained and hardcoded way.

CodePudding user response:

Html and Xml both use similar structure like:

<parent>
 <child>
 </child>
</parent>

But they are not relative to each other like typescript and java script.
Typescript and Java are meant to do the same thing, however Xml is used to store and exchange information like configs and Html is used to code Websites.

TLDR: You cant really translate Xml to Html like you would do typescript to java.

  • Related