That point you do not know XHtml (Xml + Html) grammar (DTD, XSD)

What is XHtml:

Internet excerpt word, XHTML is similar to HTML plays a role of XML.

But when XHtml template engine applications:

CYQ.Data framework set XHtmlAction template engine, used in QBlog open source blog.

Simply put, when the Html Xml carried Load to load, and then use conventional Xml syntax can be CRUD operations such as the template. 

 

Why not Html, but XHtml?

Html is not bound by strict syntax, as you do not close the label, or the label confusion, the browser can also be parsed or ignored, or misplaced, or XX;

If the direct analytic use Html, not bound by no means the rule, in case there is the possibility that the operation is too much complexity or factors considered, the cost is very high.

XHtml used, since the home Xml syntax can be used directly XmlDocument object manipulation, direct and convenient.

 

XHtml Note:

We write Html, there is often:

<meta name="robots" content="all"> 或者:<img src='http://xx.gif' border='0'>

And when XHtml bound by xml syntax:

1: individual label must have "/>" closed;

2: only attribute in double quotation marks, not in single quotes the same label to the closure.

For the template, let people make Html template generation, pay attention to this matter, is controllable little things.

 

Html with the XmlDocument operational challenges will inevitably encounter:

 

DTD(Document Type Definition)?

I used the popular workflow say, if I XmlDocument.Load (Html) to load a Html template, if with this Html & nsb; entities such as symbols, then the load will fail throw an exception as follows:

 


DTD you will remain in front of you, you just turn a blind eye:

When we create a new Html, we can see DTD tag reference in the first line:

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html  xmlns ="http://www.w3.org/1999/xhtml"   >
< head >
     < title >无标题页 </ title >
</ head >
< body >

</ body >
</ html >

You can see, by default, the address is a remote address is W3 organizations, for the browser, it resolves to the entity, but also references to DTD.

DTD browser will usually only in local integration, will not always go to remote download. 

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

 

How XmlDocument reference DTD:

Just set XmlDocument properties XmlResolver = new XmlUrlResolver (); to.

When we Load (Html), if the default dtd address (w3 points to a remote server), if read from the server every time, is bound to be undesirable, the loading speed network card will also due to a card.

DTD reference optimization, the same download to a local DTD:

In order to improve parsing speed, so the download file to a local DTD is the best practice, so if you see QBlog source project, there will be such a directory:

 

Also, to modify the remote path to a local path, we realize their XmlUrlResolver class: Here is CYQ.Data in the implementation code:

 

In fact, an inherited, rewritten URI path to the local file.

In QBlog historical task, the capture of DTD is a pretty heavy topics 

For questions DTD, relevant information very little, and the use XmlDocument to load Html encountered DTD references, it is almost not find the answer, coupled with those years, limited knowledge, so that the issue had heavy .

Even more surprising is that the entire field of teaching or teaching .NET's book, not renowned for relevant information about how the DTD:

Html teacher to teach you, do not speak from first acts of what things?

XML teach you a teacher , you do not speak from the namespace and DTD?

So what DTD is it?

If you want to see the official lengthy description of your own search keywords "dtd".

Personal understanding Simply put: is a grammatical constraints on the xml (toss rules of the game to you to let you play).

Since Html is also based on an extension of the xml, it is equally applicable to Html.

Html to Table Element Example understanding under DTD: 

For table html, normal, we all know it's common child node has tr, tbody.

That you can not have a txx, tmdxx or tmdxxx? 

答案是你可以乱加,但那是无效的,浏览器是会忽略的,因为dtd里没有定义。

如果你下载DTD到本地,可以搜到对table的语法有这么一行:

<! ELEMENT table     (caption?, (col*|colgroup*), thead?, tfoot?, (tbody+|tr+)) >

大语就是元素table的子级只能有"caption,(col、colgroup)、 thread、tfoot、(tbody,tr)“

而?*+ |就是正则里的0或1次;0或N次,1或N次,x或Y。

那么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
  
>

语法读起来,基本就是: 

summary 文字 默认(可选的)

width    长度   默认(可选的)

%Text,这里的%是个变量,往上可找一个定义:

<! ENTITY % Text "CDATA" >

语法基本上就是:CData是指字符串数据,然后把它定义为 % Text,然后其它地方引用就用%Text表示CData就是字符串了。


Html之所以为Html,那是因为有一个w3标准,用dtd给定义了所有的Html标签的元素及属性,所以A元素才有的href,Img元素有了src。

我们再回望:

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

意思是引入DTD文档,html指文档对html根元素开始生效,然后Public按字面意思理解,接着双引号的内容是一个随意起的名称,之后是一个DTD的路径。


以上说了这么多,大伙对DTD应该有一些了解了。

XSD(XML Schemas Definition)又出来了

上面刚说完,怎么又扯上XSD了,话说某组织觉的DTD在数据类型的约束上不够细腻,只有字符类型,而没有int,float,bool,date等,于是整出了另一个约束规范,就叫XSD了。

在哪可见XSD:

1: VS新建项时,可见:

 

2:Web.config的约束文件: DotNetConfig.xsd

对于web.config,一开始我以为采用dtd约束,找了三分钟才发现,微软就采用了xsd来约束,而不是dtd。

Just path: C: \ Program Files (installation directory) \ in the Microsoft Visual Studio 8 \ the Xml \ Schemas \ DotNetConfig.xsd

If the open is a bunch of Xml and grammar:

 

Constraint syntax xsd architecture, is the most authoritative guide to Web.config, if read to understand: What web.config Detailed article, are the clouds; If you can not read, or go convenient clouds. 

Of course, I want to learn, then search for the keyword "xsd grammar."

to sum up:

This is not an encyclopedia, so just write that point my head knowledge archive, and strive to go beyond that, more comprehensive knowledge of grammar, but also their own search for relevant keywords.

 

Reproduced in: https: //my.oschina.net/secyaher/blog/274159

Guess you like

Origin blog.csdn.net/weixin_33922670/article/details/91966791