-
Notifications
You must be signed in to change notification settings - Fork 0
/
xml_tutorial.html
177 lines (170 loc) · 10.3 KB
/
xml_tutorial.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1 user-scalable=no" />
<title>XML基础知识</title>
<link href="css/normalize.css" rel="stylesheet" type="text/css" />
<script src="js/jquery.min.js"></script>
<link href="css/prism.css" rel="stylesheet"/>
<script src="js/prism.js"></script>
<script>document.write("<script src='js/version.js?" + Math.random() + "'><\/script>");</script>
</head>
<body>
<iframe id="error" src="error.html"></iframe>
<div id="divs_fixed" style="display:none;">
<!--顶栏 按钮-->
<div id="buttons">
<div id='menu_btn' class='md_btn'></div>
<div id='nav_btn' class='md_btn'></div>
</div>
<!--导航-->
<div id="nav" class="nav" data-open="3"></div>
<div id="nav_overlay"></div>
<!--顶栏-->
<div id="big_title_div" class="big">XML基础知识</div>
<div id="last_update">——更新日期 2017年4月4日——</div>
<div id="top_box"></div>
<div id="top_box_top"></div>
<div id="top_box_strutting"></div>
<!--目录-->
<div id="menu">
<li class="parent md_btn" data-menuto="cont_1">一.树结构与标签</li>
<li class="parent md_btn" data-menuto="cont_2">二.识别码和继承码</li>
<li class="parent md_btn" data-menuto="cont_3">三.默认继承</li>
</div>
</div>
<div id="cont_wrapper" style="display:none;">
<script>
// JS正常加载时隐藏error、显示cont_wrapper
$("#error").css("display", "none");
$("#cont_wrapper").css("display", "block");
$("#divs_fixed").css("display", "block");
</script>
<!--上栏-->
<div id="upper_box">
<h1>前言</h1>
<div class="content">
<ul>
<li>XML是可扩展标记语言文件的扩展名(后缀),是一种用于标记电子文件使其具有结构性的标记语言</li>
<li>之后多篇解析、教程需要用到此处知识</li>
<li>本教程由-百度贴吧<a href="http://tieba.baidu.com/home/main/?un=%E9%94%80%E9%94%8B%E9%95%9D%E9%93%B8&ie=utf-8" target="_blank">销锋镝铸</a>编写</li>
<li>更多内容请访问<a href='http://runoob.com/xml/xml-tutorial.html' target='_blank'>http://runoob.com/xml/xml-tutorial.html</a></li>
</ul>
</div>
</div>
<!--内容栏-->
<div id="content_box">
<div class="chapter" id="cont_1">
<h1>第一节 树结构与元素</h1>
<span style="font-size:10pt; display:block; font-weight:bold;">——若此节无法理解可查看前言的<a href='http://runoob.com/xml/xml-tutorial.html' target='_blank'>更多内容</a></span>
<div class="section">
<h2>1.树结构</h2>
<div class="content">
首先看此XML实例:
<pre class="language-markup line-numbers"><code><bookstore>
<book category="FANTASY">
<title lang="en">The Chronicles of Narnia</title>
<author>Clive Staples Lewis</author>
<year>1950</year>
<series count="7" />
</book>
<book category="SF">
<title lang="zh">The Three Body Problem</title>
<author>Big Liu</author>
<year>2008</year>
<series count="3" />
</book>
</bookstore></code></pre>
此实例中bookstore被称作根元素,两个book则是bookstore的两个子元素,这两个子元素被包含在根元素的开始标签<<span style="color:#c92c2c">bookstore</span>>到结束标签</<span style="color:#c92c2c">bookstore</span>>之间<br />
同理title、author、year、series都是book的子元素,对于这些元素来说book则是它们的父元素,因为它们拥有相同的父元素,所以它们互称同胞<br />
某元素的父元素、父元素的父元素、等等则被称为先辈,例如bookstore和book是title的先辈<br />
某元素的子元素、子元素的子元素、等等则被称为后代,例如book、title、author是bookstore的后代<br />
</div>
</div>
<div class="section">
<h2>2.元素</h2>
<div class="content">
XML元素指的是从(且包括)开始标签直到(且包括)结束标签的部分,必须包含:
<ol style="margin:10px;">
<li>开始标签和结束标签或一个自结束标签:所有元素必须得到结束,否则错误。</li>
<ul style="font-size:10pt;">
<li>开始标签:特点是标签开头或结尾没有“/”符号,例如上例中的<<span style="color:#c92c2c">bookstore</span>>、<<span style="color:#c92c2c">book</span> <span style="color:#2f9c0a">category</span>="<span style="color:#1990b8">FANTASY</span>">等</li>
<li>结束标签:特点是标签开头有“/”符号,例如上例中的</<span style="color:#c92c2c">title</span>>、</<span style="color:#c92c2c">book</span>>等</li>
<li>自结束标签:特点是标签结尾有“/”符号,例如上例中的<<span style="color:#c92c2c">series</span> <span style="color:#2f9c0a">count</span>="<span style="color:#1990b8">7</span>" />,该标签本身构成一个元素,因此无法拥有下文提到的文本、其他元素</li>
</ul>
<li>元素名称:放在标签开头处
</ol>
不一定包含:
<ol style="margin:10px;">
<li>属性:例如上例中的<span style="color:#2f9c0a">category</span>="<span style="color:#1990b8">FANTASY</span>"就是它所在<span style="color:#c92c2c">book</span>元素的属性,其中<span style="color:#2f9c0a">category</span>是属性名称,<span style="color:#1990b8">FANTASY</span>是属性的值,属性的值必须加引号;属性位于开始标签或自结束标签之中</li>
<li>文本:例如上例中的The Chronicles of Narnia,位于第一个title元素的开始标签与结束标签之间</li>
<li>其他元素:例如子元素、后代元素</li>
</ol>
注意:元素之间必须正确嵌套,一个元素的子元素的结束标签不能出现在该元素的结束标签之后,例如下例是错误的
<pre class="language-markup line-numbers"><code><Father>
<Son>
</Father>
</Son></code></pre>
</div>
</div>
</div>
<div class="chapter" id="cont_2">
<h1>第二节 识别码和继承码</h1>
<div class="section">
<h2>识别码</h2>
<div class="content">
Database.xml中大部分元素都有Guid这个属性,它的全名是全局唯一标识符,这里为了方便称呼称为识别码;作用是使一个元素具有唯一性,能被被识别,因此不可重复。<br />
它的格式为“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”,其中每个 x 是 0-9 或 a-f 范围内的一个十六进制数。<br />
如果在载入游戏时出现“AN ITEM WITH THE SAME KEY HAS ALREADY BEEN ADDED”说明出现了重复的识别码,可以使用<a href="resources.html#cont_5.2">GUID验证器</a>来查重。
</div>
</div>
<div class="section">
<h2>继承码</h2>
<div class="content">
一个有InheritanceParent(以下称作继承码)属性的元素,会主动继承与拥有其继承码的值相同识别码值的所有内容,以下把前者称作子对象,后者称作父对象。如果子对象的已有内容和父对象的内容冲突(即都有一样的元素),则子对象继承而来的内容无效,原先有的内容生效。<br />
<h3>举例说明</h3>
<pre class="language-markup line-numbers"><code><Folder Name="A" Guid="1950"> <!--识别码为1950的文件夹A(此例标识码和继承码不按照标准)-->
<File Name="b" Author="Peter" /> <!--作者(Author)为Peter的文件a-->
<File Name="c" Author="Susan" /> <!--作者为Susan的文件b-->
</Folder>
<Folder Name="d" InheritanceParent="1950"> <!--继承码为1950的文件夹B-->
<File Name="b" Author="Edmund" /> <!--作者为Edmund的文件b-->
<File Name="c" Author="Lucy" /> <!--作者为Lucy的文件c-->
</Folder></code></pre>
从这一段代码可以看出文件夹d继承到了来自文件夹A的作者为Peter的文件a和作者为Susan的文件b,但是继承来的文件b与已有的文件b相冲突,此时优先保留原有的文件c,即文件夹B的实际代码为
<pre class="language-markup line-numbers"><code><Folder Name="d" InheritanceParent="1950"> <!--识别码为1950的文件夹B-->
<File Name="a" Author="Peter" /> <!--作者为Peter的文件a-->
<File Name="b" Author="Edmund" /> <!--作者为Edmund的文件b-->
<File Name="c" Author="Lucy" /> <!--作者为Lucy的文件c-->
</Folder></code></pre>
</div>
</div>
</div>
<div class="chapter" id="cont_3">
<h1>第三节 默认继承</h1>
<div class="section">
<div class="content">
当一个元素没有继承码属性时,那么它将默认继承其父元素的父对象中相对应元素的内容,实例:<br />
<pre class="language-markup line-numbers"><code><EntityTemplate Name="LandAnimal" Guid="e4275171-a39f-413f-8888-4c472868364d" InheritanceParent="3f077159-f492-419b-859a-bb051de6339f">
<MemberComponentTemplate Name="Mount" Guid="d7855ac3-4c88-4e86-8018-83155cd7bfbc">
<Parameter Name="MountOffset" Guid="3b86ca1c-1765-4fd7-ad58-6f52d9651188" Value="0,1.35,0" Type="Microsoft.Xna.Framework.Vector3" />
</MemberComponentTemplate>
...
</EntityTemplate>
<EntityTemplate Name="AICreature" Guid="3f077159-f492-419b-859a-bb051de6339f" InheritanceParent="bc5be211-c1f8-4e50-9ffb-4fde625d2692">
<MemberComponentTemplate Name="Mount" Guid="d7655ac3-4c88-4e89-8018-83155cd7bfbc" InheritanceParent="d0b14127-39ce-4490-af00-fb4111e9c51e">
<Parameter Name="DismountOffset" Guid="3be6ca1c-17c5-4fd7-ad58-6f52d9651188" Value="1.5,0.3,0" Type="Microsoft.Xna.Framework.Vector3" />
</MemberComponentTemplate>
...
</EntityTemplate></code></pre>
LandAnimal的父对象是AICreature,因此LandAnimal中的Mount就会继承得到AICreature中Mount的DismountOffset。<br />
</div>
</div>
</div>
<br />
</div>
</div>
<script>document.write("<script src='js/delayload.js?" + ver + "'><\/script>");</script>
</body>
</html>