扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:冷枫 来源:CSDN 2007年9月24日
关键字:
在本页阅读全文(共2页)
文件7为part元素定义了一个缺省属性approved(红色字体),在规范化的文档中,缺省属性必须出现在元素的属性中。文件8时规范化后的文件。
文件8
<?xml version="1.0"?>
<!DOCTYPE product [
<!ATTLIST part approved CDATA "yes">
<!ENTITY testhistory "Part has been tested according to the specified standards.">
]>
<product xmlns="http://www.myFictitiousCompany.com/product"
xmlns:sup="http://www.myFictitiousCompany.com/supplier"
name="rotating disc "e;Energymeter"e;"
id="P 184.435"
classification = "MeasuringInstruments/Electrical/Energy/">
<parts>
<part id="P 184.675"
name="bearing"
approved="yes">
<sup:supplier id="S 1753"/>
<sup:supplier id="S 2341"/>
<sup:supplier id="S 3276"/>
<comments>Part has been tested according to the specified standards.</comments>
</part>
<part id="P 184.871"
name="magnet"
xmlns="http://www.myFictitiousCompany.com/product"
approved="yes">
<sup:supplier id="S 3908"/>
<sup:supplier id="S 4589"/>
<sup:supplier id="S 1098"/>
<comments>Part has been tested according to the specified standards.</comments>
</part>
</parts>
</product>
9 XML和DTD声明
规范化的XML文档不能存在XML或DTD声明,文件9是将XML和DTD声明去除后的文件。
文件9
<product xmlns="http://www.myFictitiousCompany.com/product"
xmlns:sup="http://www.myFictitiousCompany.com/supplier"
name="rotating disc "e;Energymeter"e;"
id="P 184.435"
classification = "MeasuringInstruments/Electrical/Energy/">
<parts>
<part id="P 184.675"
name="bearing"
approved="yes">
<sup:supplier id="S 1753"/>
<sup:supplier id="S 2341"/>
<sup:supplier id="S 3276"/>
<comments>Part has been tested according to the specified standards.</comments>
</part>
<part id="P 184.871"
name="magnet"
xmlns="http://www.myFictitiousCompany.com/product"
approved="yes">
<sup:supplier id="S 3908"/>
<sup:supplier id="S 4589"/>
<sup:supplier id="S 1098"/>
<comments>Part has been tested according to the specified standards.</comments>
</part>
</parts>
</product>
10 文档元素外的空格
规范化的XML文档在文档元素外面不能存在空格,文档以“<”开始,在"<"前面不能有空格。文件10时去掉“<”前面的空格后的文件。
文件10
<product xmlns="http://www.myFictitiousCompany.com/product" xmlns:sup="http://www.myFictitiousCompany.com/supplier"
name="rotating disc "e;Energymeter"e;" id="P 184.435"
classification="MeasuringInstruments/Electrical/Energy/">
<parts>
<part id="P 184.675" name="bearing" approved="yes">
<sup:supplier id="S 1753"/>
<sup:supplier id="S 2341"/>
<sup:supplier id="S 3276"/>
<comments>Part has been tested according to the specified standards.</comments>
</part>
<part id="P 184.871" name="magnet" xmlns="http://www.myFictitiousCompany.com/product" approved="yes">
<sup:supplier id="S 3908"/>
<sup:supplier id="S 4589"/>
<sup:supplier id="S 1098"/>
<comments>Part has been tested according to the specified standards.</comments>
</part>
</parts>
</product>
11 开始和结束元素中的空格
1 ) "<"与元素名之间不能存在空格,"</"也一样。
2 ) 如果元素包含属性,在元素名和属性之间有且只有一个空格。
3 ) 在属性和属性值之间的等号两边不能有空格。
4 ) 属性值和相邻属性之间有且只有一个空格。
5 ) 在">"之前不能有空格。
12 空元素
规范化的xml文档中,空元素要以<...></...>的形式出现,将<emptyElement/>转化为<emptyElement></emptyElement>后得到文件11。
文件11
<product xmlns="http://www.myFictitiousCompany.com/product" xmlns:sup="http://www.myFictitiousCompany.com/supplier"
name="rotating disc "Energymeter"" id="P 184.435" classification="MeasuringInstruments/Electrical/Energy/">
<parts>
<part id="P 184.675" name="bearing" approved="yes">
<sup:supplier id="S 1753"></sup:supplier>
<sup:supplier id="S 2341"></sup:supplier>
<sup:supplier id="S 3276"></sup:supplier>
<comments>Part has been tested according to the specified standards.</comments>
</part>
<part id="P 184.871" name="magnet" xmlns="http://www.myFictitiousCompany.com/product" approved="yes">
<sup:supplier id="S 3908"></sup:supplier>
<sup:supplier id="S 4589"></sup:supplier>
<sup:supplier id="S 1098"></sup:supplier>
<comments>Part has been tested according to the specified standards.</comments>
</part>
</parts>
</product>
13 名称空间声明
XML文档规范化要求文档中除了多余的名称空间外,所有的名称空间都保留。文件11中第二个part元素的名称空间是多余的,将她出去不会影响文档中所有节点的名称空间上下文。
文件12
<product xmlns="http://www.myFictitiousCompany.com/product" xmlns:sup="http://www.myFictitiousCompany.com/supplier"
name="rotating disc "Energymeter"" id="P 184.435" classification="MeasuringInstruments/Electrical/Energy/">
<parts>
<part id="P 184.675" name="bearing" approved="yes">
<sup:supplier id="S 1753"></sup:supplier>
<sup:supplier id="S 2341"></sup:supplier>
<sup:supplier id="S 3276"></sup:supplier>
<comments>Part has been tested according to the specified standards.</comments>
</part>
<part id="P 184.871" name="magnet" approved="yes">
<sup:supplier id="S 3908"></sup:supplier>
<sup:supplier id="S 4589"></sup:supplier>
<sup:supplier id="S 1098"></sup:supplier>
<comments>Part has been tested according to the specified standards.</comments>
</part>
</parts>
</product>
14 元素属性的排序
XML文档规范化要求元素的属性以字母的升序排列,在一个元素中,名称空间首先出现,然后是属性名和属性值,文件13是排列后的文件
文件13
<product xmlns="http://www.myFictitiousCompany.com/product" xmlns:sup="http://www.myFictitiousCompany.com/supplier"
classification="MeasuringInstruments/Electrical/Energy/" id="P 184.435" name="rotating disc "Energymeter"">
<parts>
<part approved="yes" id="P 184.675" name="bearing">
<sup:supplier id="S 1753"></sup:supplier>
<sup:supplier id="S 2341"></sup:supplier>
<sup:supplier id="S 3276"></sup:supplier>
<comments>Part has been tested according to the specified standards.</comments>
</part>
<part approved="yes" id="P 184.871" name="magnet">
<sup:supplier id="S 3908"></sup:supplier>
<sup:supplier id="S 4589"></sup:supplier>
<sup:supplier id="S 1098"></sup:supplier>
<comments>Part has been tested according to the specified standards.</comments>
</part>
</parts>
</product>
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=356379
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。