Comparison of XML and HTML

  • HTML has fixed tags to display formatting, structure, semantics and other tags.
    XML is a meta-markup language, so it can be created by users and is more flexible.

    For example: define a book information in HTML:
<dt>畅销榜单</dt>
<dd>NO.1</dd>
<ul>
	<li>书名:《悲惨世界》</li>
	<li>作者:雨果</li>
</ul>

The same representation information can be written in XML as:

<BookList>畅销榜单</BookList>
<top>NO.1</top>
<info>
	<BookName>书名:《悲惨世界》</BookName>
	<BookAuthor>作者:雨果</BookAuthor>
</info>

The above <dd> </dd>may be <BookList> <BookList>Tags, that is, tags.
It can be seen that using XML can make the code more readable and more convenient to use through custom tags.

For web page display functions, HTML is stronger than XML,
but in terms of file applications, XML is stronger than HTML.

  • Identifiers are nested differently

The following sample program fragments are often seen in HTML

<t><foo> example <t><foo>

Carefully observe the nesting order of this code.
This is obviously wrong in XML and must be written as:

<t><foo> example <foo><t>
  • The use of quotation marks for attribute values ​​is different.
    In HTML, attribute values ​​can be used without quotation marks, for example
<font color=red>

This is wrong in XML and should be expressed as:

<font color="red">
  • Different handling of blank characters
    Code example 1:
<author>雨果</author>

Code example 2:

<author>
	雨果
</author>

For HTML, the parser will remove the whitespace in the sentence, so the execution results of Code 1 and Code 2 are the same.
But for XML, the parser will be faithfully handed over to the application to understand. Therefore, the parser will retain all the whitespace characters in the content and pass them to the application without modification, but the whitespace in element tags and attribute values ​​will be deleted.

Guess you like

Origin blog.csdn.net/weixin_44895666/article/details/108681774