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"/>
|
分享到:
相关推荐
DTD(Document Type Definition)和XSD(XML Schema Definition)是两种用来定义XML文档结构和数据类型的规范。 1. XML DTD:DTD是XML的早期规范,用于定义XML文档的元素、属性以及它们之间的关系。它通过一系列...
XML转XSD\DTD工具 W3C XML Schema XSD 工具
DTD(文档类型定义)和XSD(XML Schema)是两种验证XML文档结构和内容的重要工具。 首先,XML是一种自描述性的标记语言,它允许用户自定义标签来表示数据,使得数据更易于理解和处理。XML文档的结构严谨,每个元素...
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 Schema 的优势在于它的可扩展性和强大的数据类型支持,使得它比 DTD 更加适合大型、复杂的 XML 应用场景。由于 XML Schema 本身是基于 XML 的,因此可以利用 XML 工具进行编辑、解析和处理,增加了灵活性和便利...
### XML与DTD详解 #### 一、XML简介 XML(Extensible Markup Language)是一种非常重要的数据交换标准,它被广泛应用于互联网数据交换场景之中。XML的设计初衷是为了传输和存储数据,其灵活性允许用户自定义标签,...
DTD(文档类型定义)是XML的一个重要组成部分,它定义了XML文档的结构和规则。DTD通过声明元素、属性以及它们之间的关系,来确保XML文档的合法性。例如,一个DTD可以规定某个元素必须包含哪些子元素,或者元素是否...
XML Schema 和 XML DTD 是两种用于定义XML文档结构和数据约束的语言。XML DTD(文档类型定义)是较早出现的规范,而XML Schema则在2001年成为W3C的正式推荐标准,旨在提供更强大和灵活的XML文档验证功能。 首先,...
DTD(Document Type Definition)文件和XSD(XML Schema Definition)文件是XML文档结构的重要定义工具,它们用于规范XML文档的结构和数据类型。在给定的压缩包文件中,我们看到的是与Java Web开发框架Struts 2和...
在XML中,DTD(Document Type Definition)是一种定义XML文档结构的规范,它规定了XML文档的元素和属性的规则。DTD可以帮助确保XML文档的合法性,即文档是否遵循了预定义的结构。 XML DTD的编写可以分为内部DTD和...
在WEB编程技术中,CSS(层叠样式表)、DTD(文档类型定义)、XSD(XML架构定义)和XML(可扩展标记语言)是至关重要的组成部分。这些技术共同为创建高效、结构化的网页提供了坚实的基础。 首先,CSS是用于描述HTML...
### 在Eclipse中导入DTD和XSD文件,实现XML自动提示 #### 一、概述 在Eclipse等IDE中开发基于XML技术的应用时,为了提高编码效率和代码质量,我们通常会利用IDE提供的智能提示功能。这需要我们将相关的DTD...
本示例将深入探讨XML的使用方式,包括XSL、XSD和DTD等关键组件。 1. **XML基本结构** XML文档由一系列元素构成,每个元素通过标签括起来,例如 `<element>` 和 `</element>`。元素可以包含其他元素、文本、属性...
XML DTD(Document Type Definition)和XML Schema是两种主要的XML语义约束机制,用于定义XML文档的结构和数据类型。 XML DTD是最早的XML文档类型定义方式,它使用一套预定义的元素和属性来描述XML文档的结构。DTD...
XML入门精解之DTD 文件格式定义(XML DTD) DTD实际上可以看作一个或多个XML文件的模板,这些XML文件中的元素、元素的属性、元素的排列方式/顺序、元素能够包含的内容等,都必须符合DTD中的定义。XML文件中的元素,...
本文将深入探讨如何使用Castor解析XML,并通过XSD(XML Schema Definition)进行XML校验。 ### Castor XML解析 1. **安装与配置**:首先,你需要在项目中引入Castor的依赖库。如果你使用的是Maven,可以在pom.xml...
DTD(Document Type Definition)是XML的一个重要组成部分,它定义了XML文档的结构和规则,确保XML文档的合法性。HTML(HyperText Markup Language)则是用于创建网页的标准标记语言,它关注的是如何在浏览器中展示...
使用DTD验证XML文档 一、 DTD的定义: a) DTD是Document Type Defintion的缩写,即文档类型定义。DTD用来描述XML文档的结构。 二、 DTD可能包含的内容: a) 元素的定义规则。 b) 元素之间的关系规则。 c) 属性的定义...
DTD(Document Type Definition)是XML的一个重要组成部分,它定义了XML文档的结构和规则,确保文档的合法性。在本实例中,我们将深入探讨XML与DTD之间的关系,包括内部DTD和外部DTD的使用。 首先,我们来理解什么...