The XHtml (Xml + Html) syntax basics You Don't Know (DTD, XSD)

Source: Internet
Author: User

What is XHtml:

To extract a sentence from the Internet, XHTML is an XML that plays a role similar to HTML.

XHtml can be used as a template engine application:

The CYQ. Data framework has a set of XHtmlAction template engines applied to QBlog open-source blogs.

Simply put, when loading Html into Xml, you can add, delete, modify, and query the template using the regular Xml syntax.

Why is it not Html, but XHtml?

The syntax constraints of Html are not strict. If your tag is not closed, or the tag is disordered, it can also be parsed, ignored, misplaced, or XX by the browser;

If Html is used for parsing directly, no constraints mean no rules. There is a possibility that operations may be complicated or there are too many factors to consider. The cost is quite high.

Because the syntax of XHtml is Xml, you can directly use the XmlDocument object to manipulate it.

XHtml considerations:

When we write Html, there are often:

<Meta name = "robots" content = "all"> or:

When XHtml is subject to xml syntax constraints:

1: separate labels must be "/>" closed;

2: The attribute can only be enclosed by double quotation marks, but cannot be enclosed by single quotation marks.

For a template, It is a controllable thing to let the person who creates and generates the Html template pay attention to this matter.

The following problems must be encountered when operating Html with XmlDocument:

DTDDocument Type Definition )?

In general, if I use XmlDocument. LoadHtml to load an Html template, if the Html contains Entity symbols such as & nsb;, the loading will fail and an exception will be thrown as follows:

DTD is always in front of you, but you turn a blind eye to it:

When we create an Html file, we can see the reference tag of the DTD In the first line:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "">
<Html xmlns = "">
<Title> No title page </title>


It can be seen that the W3 Organization provides the address by default. The address is also a remote address. For a browser, it needs to parse the object and reference the DTD.

However, browsers usually integrate the DTD locally and do not remotely download the DTD each time.

Similarly, when we need to operate Html, we need to introduce this DTD file.

How to reference DTD in XmlDocument:

Set XmlResolver = new XmlUrlResolver.

When LoadHtml), if the dtd address is directed to the remote w3 server by default), it is not advisable to read data from the server every time, the loading speed will also become stuck on the network.

The DTD reference optimization also downloads the DTD to the local device:

To speed up parsing, it is the best practice to download the DTD file to a local machine. If you see the source code project of QBlog, there will also be a directory like this:

Similarly, to change the remote path to a local path, we implement our own XmlUrlResolver class: The implementation code in CYQ. Data is as follows:

It is actually an inheritance. Rewrite the URI path to point to the local file.

In the history tasks of QBlog, it is a very heavy task to conquer DTD.

There are very few questions about DTD, and the question about DTD reference when loading Html using XmlDocument is almost impossible to find the answer. In addition, due to those years, knowledge is limited, so we have to say that the subject is heavy.

What's more strange is that there is not much information about DTD in the teaching or teaching books of. NET in the entire field:

The teacher who taught you Html never talked about the first behavior?

Teach you XMLInstructor, Never talk about namespaces and DTD?

So what is DTD?

If you want to see the official long description, please search for the keyword "dtd" by yourself.

In my personal understanding, Simply put: it is a syntax constraint on xml, and a game rule is required for you to play ).

Because Html is also based on an extension of xml, it is also applicable to Html.

Take the Table element example in Html to learn about the DTD:

For an html table, we all know that its common subnodes are tr and tbody.

Can it have a txx, tmdxx, or tmdxxx?

The answer is that you can add it in disorder, but it is invalid. The browser will ignore it because it is not defined in the dtd.

If you download the DTD to a local machine, you can find the syntax for the table as follows:

<! ELEMENT table (caption ?, (Col * | colgroup *), thead ?, Tfoot ?, (Tbody + | tr +)>

The syntax is that the sub-level of the element table can only include "caption, col, colgroup), thread, tfoot, tbody, tr)"

And? * + | 0 or 1 times in the regular expression; 0 or N times, 1 or N times, x or Y.

What are the attributes of a Table?

<! ATTLIST table
% Attrs;
Summary % Text; # IMPLIED
Width % Length; # IMPLIED
Border % Pixels; # IMPLIED
Frame % TFrame; # IMPLIED
Rules % TRules; # IMPLIED
Cellspacing % Length; # IMPLIED
Cellpadding % Length; # IMPLIED
Align % TAlign; # IMPLIED
Bgcolor % Color; # IMPLIED

The syntax is basically:

Summary text is optional by default)

Width length (optional by default)

% Text. Here % is a variable. You can find a definition above:

<! ENTITY % Text "CDATA">

The syntax is basically: CData refers to the string data, and then defines it as % Text. Then, if it is referenced elsewhere, % Text indicates that CData is the string.

The reason why Html is that there is A w3 standard and dtd is used to define the elements and attributes of all Html tags. Therefore, elements A have href and Img have src.

Let's look back:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "">

This document introduces a DTD document. html indicates that the document takes effect on the html root element, and then Public is understood literally. Then the content of double quotation marks is a random name, followed by a DTD path.

As mentioned above, everyone should have some knowledge about the DTD.

XSDXML Schemas Definition) again

After talking about the above, how can we talk about XSD? In other words, the DTD of a certain organization is not delicate enough in terms of data type constraints. It only has character types, but does not have int, float, bool, date, etc, therefore, an XSD is defined as another constraint specification.

Where can I see XSD:

1: VS when creating a new item, it is visible:

2: constraint file of Web. config: DotNetConfig. xsd

For web. config, I initially thought it was using the dtd constraint. After three minutes, I found that Microsoft adopted the xsd constraint instead of the dtd.

Path: C: \ Program Files (installation directory) \ Microsoft Visual Studio 8 \ Xml \ Schemas \ DotNetConfig. xsd

If it is opened, there are a bunch of Xml syntaxes:

The constraint syntax of the xsd architecture is Web. the most authoritative guide to config. the articles described in config are full of clouds. If you cannot understand them, it is easier to see them.

If you want to learn, search for the keyword "xsd Syntax".


This article is not an encyclopedia, so I only write the point of Knowledge archived in my mind, and strive to point to the end, more complete syntax knowledge, please also search for relevant keywords on your own.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.