http://www.w3schools.com/schema/schema_intro.asp
http://www.w3schools.com/xml/default.asp
http://www.w3schools.com/dtd/default.asp
http://www.w3schools.com/
XML was designed to transport and store data.
HTML was designed to display data.
The declaration is not a part of the XML document itself, and it has no closing tag
XML Tags are Case Sensitive
Entity References
Some characters have a special meaning in XML.
If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element.
only < is illegal..
With XML, White Space is Preserved
XML Stores New Line as LF
In Unix applications, a new line is normally stored as a LF character.
Macintosh applications use only a CR character to store a new line.
Windows use both CR and LF to store a new line.
attributes cannot contain multiple values (elements can)
attributes cannot contain tree structures (elements can)
attributes are not easily expandable (for future changes)
XML with correct syntax is "Well Formed" XML.
XML validated against a DTD is "Valid" XML.
A DTD can be declared inline inside an XML document, or as an external reference.
<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>
(there must be a space character after the element name .)
Seen from a DTD point of view, all XML documents (and HTML documents) are made up by the following building blocks:
- Elements
- Attributes
- Entities
- PCDATA (PCDATA means parsed character data.The text will be examined by the parser for entities and markup.)
- CDATA (Tags inside the text will NOT be treated as markup and entities will not be expanded.)
<!ELEMENT element-name category>
or
<!ELEMENT element-name (element-content)>
|
Empty Elements
<!ELEMENT element-name EMPTY>
Example:
<!ELEMENT br EMPTY>
Elements with Parsed Character Data
<!ELEMENT element-name (#PCDATA)>
Example:
<!ELEMENT from (#PCDATA)>
Elements with Parsed Character Data
<!ELEMENT element-name ANY>
Example:
<!ELEMENT note ANY>
Elements with Children (sequences)
<!ELEMENT element-name (child1)>
or
<!ELEMENT element-name (child1,child2,...)>
Example:
<!ELEMENT note (to,from,heading,body)>
When children are declared in a sequence separated by commas, the children must appear in the same sequence in the document
Declaring Only One Occurrence of an Element
<!ELEMENT element-name (child-name)>
|
Declaring Minimum One Occurrence of an Element
<!ELEMENT element-name (child-name+)>
Declaring Zero or More Occurrences of an Element
<!ELEMENT element-name (child-name*)>
|
Declaring Zero or One Occurrences of an Element
<!ELEMENT element-name (child-name?)>
|
Declaring either/or Content
<!ELEMENT note (to,from,header,(message|body))>
Declaring Mixed Content
<!ELEMENT note (#PCDATA|to|from|header|message)*>
DTD - Attributes
In a DTD, attributes are declared with an ATTLIST declaration.
Declaring Attributes
<!ATTLIST element-name attribute-name attribute-type default-value>
DTD example:
<!ATTLIST payment type CDATA "check">
XML example:
<payment type="check" />
The attribute-type can be one of the following:
TypeDescription
CDATA
|
The value is character data
|
(en1|en2|..)
|
The value must be one from an enumerated list
|
ID
|
The value is a unique id
|
IDREF
|
The value is the id of another element
|
IDREFS
|
The value is a list of other ids
|
NMTOKEN
|
The value is a valid XML name
|
NMTOKENS
|
The value is a list of valid XML names
|
ENTITY
|
The value is an entity
|
ENTITIES
|
The value is a list of entities
|
NOTATION
|
The value is a name of a notation
|
xml:
|
The value is a predefined xml value
|
The default-value can be one of the following:
ValueExplanation
value
|
The default value of the attribute
|
#REQUIRED
|
The attribute is required
|
#IMPLIED
|
The attribute is not required
|
#FIXED value
|
The attribute value is fixed
|
<!ATTLIST to content (tw|china|USA|English) "china">
<!ATTLIST note type CDATA #REQUIRED>
dispaly xml with css or xsl.
Use attribute instead of element when dealt with id .
DTD - Entities
Entity references are references to entities
Entities can be declared internal or external
<!ENTITY entity-name "entity-value">
XML Namespaces - The xmlns Attribute
Name conflicts in XML can easily be avoided using a name prefix.
<h:table xmlns:h="http://www.w3.org/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
Default Namespaces
<table xmlns="http://www.w3.org/TR/html4/">
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
Namespaces in Real Use
XSLT is an XML language that can be used to transform XML documents into other formats, like HTML.
In the XSLT document below, you can see that most of the tags are HTML tags.
The tags that are not HTML tags have the prefix xsl, identified by the namespace xmlns:xsl="http://www.w3.org/1999/XSL/Transform":
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr>
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
|
XSD:
With an extensible Schema definition you can:
- Reuse your Schema in other Schemas
- Create your own data types derived from the standard types
- Reference multiple schemas in the same document
The <schema> element may contain some attributes. A schema declaration often looks something like this:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
...
...
</xs:schema>
|
The following fragment:
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
indicates that the elements and data types used in the schema come from the "http://www.w3.org/2001/XMLSchema" namespace. It also specifies that the elements and data types that come from the "http://www.w3.org/2001/XMLSchema" namespace should be prefixed with xs:
This fragment:
targetNamespace="http://www.w3schools.com"
|
indicates that the elements defined by this schema (note, to, from, heading, body.) come from the "http://www.w3schools.com" namespace.
This fragment:
xmlns="http://www.w3schools.com"
|
indicates that the default namespace is "http://www.w3schools.com".
This fragment:
elementFormDefault="qualified"
|
indicates that any elements used by the XML instance document which were declared in this schema must be namespace qualified.
Defining a Simple Element
The syntax for defining a simple element is:
<xs:element name="xxx" type="yyy"/>
|
Default and Fixed Values for Simple Elements
In the following example the default value is "red":
<xs:element name="color" type="xs:string" default="red"/>
|
In the following example the fixed value is "red":
<xs:element name="color" type="xs:string" fixed="red"/>
|
分享到:
相关推荐
xml dtd xsd 的编写 标准格式可以供学习参考用
XML转XSD\DTD工具 W3C XML Schema XSD 工具
上课的实例,我觉得很不错。是在eclipse里面写的
java -jar trang.jar -I rng|rnc|dtd|xml -O rng|rnc|dtd|xsd [其它参数] 输入文件名 输出文件名 -I : 输入文件的格式 -O : 输出文件的格式 必须是大写,小写不识别 命令如:java -jar trang.jar -I xml -O xsd D:\...
XML大作业 图书馆xml dtd xsl xsd 有效性检测 算平均值 DOM解析 等 内含源代码 截图显示
xml与DTD,xml与DTD,xml与DTD,xml与DTD
在Eclipse中导入dtd和xsd文件,使XML自动提示 DTD 类型约束文件 1. Window->Preferences->XML->XML Catalog->User Specified Entries窗口中,选择Add 按纽 2.在Add XML Catalog Entry 对话框中选择或输入以下...
XML例子 DTD例子 XSL例子 XLD例子 DOM解析
XML入门精解之DTD 文件格式定义(XML DTD) DTD实际上可以看作一个或多个XML文件的模板,这些XML文件中的元素、元素的属性、元素的排列方式/顺序、元素能够包含的内容等,都必须符合DTD中的定义。XML文件中的元素,...
使用DTD验证XML文档 一、 DTD的定义: a) DTD是Document Type Defintion的缩写,即文档类型定义。DTD用来描述XML文档的结构。 二、 DTD可能包含的内容: a) 元素的定义规则。 b) 元素之间的关系规则。 c) 属性的定义...
初级WEB编程技术内容, 包括css.dtd.xsd.xml及实验报告封面的xml编写程序
xml dtd html 源程序 数据与模版 生成 html
XML Schema 与 XML DTD的技术比较与分析XML Schema 与 XML DTD的技术比较与分析
XML、DTD、Schema笔记、使用方法、注意事项,尤其是对XML和DTD比较详细
XML Schema 是DTD的替代品。XML Schema语言也就是XML Schema Definition (XSD)。 XML Schema描述了XML文档的结构。可以用一个指定的XML Schema来验证某个XML文档,以检查该XML文档是否符合其要求。文档设计者可以...
关于XML中DTD的简单写法,包括引用外部DTD之类的典型说明
与xml相关内部dtd与外部dtd实例,内部dtd调用与外部dtd调用实例!
关于XML的DTD教程,关于XML的DTD教程,关于XML的DTD教程
dtd例子xmldtd
XML DTD和XmlSchema标准参考手册!!!!!!!!!!!!!!!!!!!!!!