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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
|
<?xml version="1.0" encoding="UTF-8"?>
<!--
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
*
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at
* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
*
-->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="XMLObjects" xml:lang="ja">
<refnamediv>
<refname>XML Objects</refname>
<refpurpose>異なるのXMLオブジェクトのプロパティを記述する</refpurpose>
</refnamediv>
<refsection>
<title>内容</title>
<itemizedlist>
<listitem>
<para>
<link linkend="XMLDocument">XML文書</link>
</para>
</listitem>
<listitem>
<para>
<link linkend="XMLElement">XML要素</link>
</para>
</listitem>
<listitem>
<para>
<link linkend="XMLAttributes">XML属性</link>
</para>
</listitem>
<listitem>
<para>
<link linkend="XMLNamespace">XML名前空間</link>
</para>
</listitem>
<listitem>
<para>
<link linkend="XMLNodeList">XMLノードリスト</link>
</para>
</listitem>
<listitem>
<para>
<link linkend="XMLNodeSet">XML XPath結果セット</link>
</para>
</listitem>
<listitem>
<para>
<link linkend="XMLValid">XML検証ファイル</link>
</para>
</listitem>
</itemizedlist>
</refsection>
<refsection>
<title>説明</title>
<para>ノードおよびそのプロパティをアクセスおよび修正可能です.</para>
</refsection>
<refsection id="XMLDocument">
<title>XML文書</title>
<para>XML文書は以下の2つのプロパティを有します: root および url
<itemizedlist>
<listitem>
<para>
<emphasis role="bold">root</emphasis>: 文書のルート要素で, XML要素です;
</para>
</listitem>
<listitem>
<para>
<emphasis role="bold">url</emphasis>: urlは文字列で,
存在する場合は文書のURL,未定義の場合は空文字列となります.
</para>
</listitem>
</itemizedlist>
</para>
<programlisting role="example"><![CDATA[
doc = xmlReadStr("<root><a att=""foo"" rib=""bar""><b>Hello</b></a></root>");
doc.root = doc.root.children(1);
xmlDump(doc)
doc.url = TMPDIR+"/foo.xml";
doc
xmlWrite(doc);
xmlDelete(doc);
]]></programlisting>
</refsection>
<refsection id="XMLElement">
<title>XML要素</title>
<para>XML要素は以下の7つのプロパティを有します:
<itemizedlist>
<listitem>
<para>
<emphasis role="bold">name</emphasis>: タグ名;
</para>
</listitem>
<listitem>
<para>
<emphasis role="bold">namespace</emphasis>: XML名前空間オブジェクト;
</para>
</listitem>
<listitem>
<para>
<emphasis role="bold">content</emphasis>:
ノードの内容を表す文字列.
例えば,<A>hello <B>world</B> というノードA
の内容は文字列 "hello world"となります.
</para>
</listitem>
<listitem>
<para>
<emphasis role="bold">type</emphasis>:
ノードの型を表す文字列. 以下の値のどれかとなります:
"XML_ELEMENT_NODE", "XML_ATTRIBUTE_NODE", "XML_TEXT_NODE", "XML_CDATA_SECTION_NODE", "XML_ENTITY_REF_NODE", "XML_ENTITY_NODE", "XML_PI_NODE", "XML_COMMENT_NODE", "XML_DOCUMENT_NODE", "XML_DOCUMENT_TYPE_NODE", "XML_DOCUMENT_FRAG_NODE", "XML_NOTATION_NODE", "XML_HTML_DOCUMENT_NODE", "XML_DTD_NODE", "XML_ELEMENT_DECL", "XML_ATTRIBUTE_DECL", "XML_ENTITY_DECL", "XML_NAMESPACE_DECL", "XML_XINCLUDE_START", "XML_XINCLUDE_END", "XML_DOCB_DOCUMENT_NODE".
</para>
</listitem>
<listitem>
<para>
<emphasis role="bold">parent</emphasis>: 親XML要素;
</para>
</listitem>
<listitem>
<para>
<emphasis role="bold">attributes</emphasis>:
XML属性オブジェクトとして表したノード属性;
</para>
</listitem>
<listitem>
<para>
<emphasis role="bold">children</emphasis>:
XMLノードリストオブジェクトとして表した子要素.
</para>
</listitem>
<listitem>
<para>
<emphasis role="bold">line</emphasis>:
XML要素の線の定義.
</para>
</listitem>
</itemizedlist>
<programlisting role="example"><![CDATA[
s = "<root xmlns:bar=""http://www.scilab.org/"">"+..
"<bar:a att=""foo"" rib=""bar"">"+..
"<b>Hello</b><c> world</c></bar:a></root>"
doc = xmlReadStr(s);
first = doc.root.children(1);
b = first.children(1);
// "new_attribute"という名前の属性を新規に追加
first.attributes.new_attribute = "value";
// firstの子の名前空間を表示
first.namespace
// ノードの内容を表示
first.content
// bは親を有します
b.parent
// firstに子を追加できます.
first.children(3) = b
// 整数でない添字により挿入を行えます.
first.children(1.5) = "<d> Scilab</d>"
// firstの子が上の行で定義されています...
b.line
xmlDump(first)
xmlDelete(doc);
]]></programlisting>
</para>
</refsection>
<refsection id="XMLAttributes">
<title>XML属性</title>
<para>
XML属性は,属性の名前を属性の値にマップするハッシュテーブルの一種です.
属性の値は,このオブジェクトのフィールドとして属性の名前,または
1から属性の大きさまでの添字番号によりアクセスや修正が可能です.
</para>
<programlisting role="example"><![CDATA[
s = "<root xmlns:bar=""http://www.scilab.org/"">"+..
"<bar:a att=""foo"" rib=""bar"">"+..
"<b>Hello</b><c> world</c></bar:a></root>"
doc = xmlReadStr(s);
first = doc.root.children(1);
// 属性を読み込みます
first.attributes.att
// 空の属性を設定します
first.attributes.att = "";
// 新しい属性を追加します
first.attributes.hello = "world";
// 添字を使用します
first.attributes(1) = "Bonjour";
first.attributes(1)
xmlDump(first)
xmlDelete(doc);
]]></programlisting>
</refsection>
<refsection id="XMLNamespace">
<title>XML名前空間</title>
<para>XML名前空間は以下の2つのプロパティを有します: href および prefix
<itemizedlist>
<listitem>
<para>
<emphasis role="bold">href</emphasis>: 名前空間hrefを表す文字列;
</para>
</listitem>
<listitem>
<para>
<emphasis role="bold">prefix</emphasis>:
この名前空間で使用する接頭辞を表す文字列.
</para>
</listitem>
</itemizedlist>
</para>
<programlisting role="example"><![CDATA[
s = "<root xmlns:bar=""http://www.scilab.org/"">"+..
"<bar:a att=""foo"" rib=""bar"">"+..
"<b>Hello</b><c> world</c></bar:a></root>"
doc = xmlReadStr(s);
ns = doc.root.children(1).namespace;
ns.href
ns.prefix
xmlDelete(doc);
]]></programlisting>
</refsection>
<refsection id="XMLNodeList">
<title>XMLノードリスト</title>
<para>
XMLノードリストはある要素の子に番号を付ける際に使用される
型です.各要素は整数の添字によりアクセスできます.
これはリストであるため,doubleの添字により,
新しい要素をこのリストに挿入することができます.
</para>
<para>
リストの大きさは,'size'フィールドにより取得できます.
</para>
<para>
リストの各ノードの名前または内容は'name'または'content'フィールド
により取得できます.
</para>
<programlisting role="example"><![CDATA[
doc = xmlReadStr("<root><a>Hello</a><b> world</b></root>");
c = doc.root.children;
// 2つの要素があることが確認できます
c.size
// 最初の要素を読み込みます
xmlDump(c(1))
// 特定の要素を他の要素で置換します
c(1) = "<c>Hello</c>"
// 新しい要素を最初の要素と二番目の要素の間に挿入します
c(1.5) = "<d> Scilab</d>" // 1.5 or 1.234...
// 新しい要素を末尾またはリストの先頭に挿入します
c(0) = "<e>Head </e>"
c(217) = "<f> Tail</f>"
xmlDump(c)
// ノードの名前を取得します
c.name
// ノードの内容を取得します
c.content
xmlDelete(doc);
]]></programlisting>
</refsection>
<refsection id="XMLNodeSet">
<title>XML XPath結果セット</title>
<para>
XMLノードセットは,XPathクエリから返されたオブジェクトです.
新しい要素を挿入したり,既存の要素を置換することはできません.
できることは整数の添字により要素を取得することのみです.
</para>
<para>
このセットの大きさは'size'フィールドにより取得できます.
</para>
<programlisting role="example"><![CDATA[
doc = xmlReadStr("<root><a><b>Hello</b></a><a>World</a></root>");
s = xmlXPath(doc, "//a")
s.size
s(1).content
s(2).content
// または ...
s.content
xmlDelete(doc);
]]></programlisting>
</refsection>
<refsection id="XMLValid">
<title>XML検証ファイル</title>
<para>XML検証ファイルは文書の検証に使用されるオブジェクトです.
DTD, Relax NGまたは schemaにより検証できます.
</para>
<programlisting role="example"><![CDATA[
doc = xmlRead("SCI/modules/xml/tests/unit_tests/library.xml");
dtd = xmlDTD("SCI/modules/xml/tests/unit_tests/library.dtd");
schema = xmlSchema("SCI/modules/xml/tests/unit_tests/library.xsd");
rng = xmlRelaxNG("SCI/modules/xml/tests/unit_tests/library.rng");
// 検証
xmlValidate(doc, dtd);
xmlValidate(doc, rng);
xmlValidate(doc, schema);
xmlDelete("all");
]]></programlisting>
</refsection>
<refsection role="see also">
<title>参照</title>
<simplelist type="inline">
<member>
<link linkend="xmlRead">xmlRead</link>
</member>
<member>
<link linkend="xmlReadStr">xmlReadStr</link>
</member>
<member>
<link linkend="xmlElement">xmlElement</link>
</member>
<member>
<link linkend="xmlDocument">xmlDocument</link>
</member>
<member>
<link linkend="xmlNs">xmlNs</link>
</member>
<member>
<link linkend="xmlDTD">xmlDTD</link>
</member>
<member>
<link linkend="xmlSchema">xmlSchema</link>
</member>
<member>
<link linkend="xmlRelaxNG">xmlRelaxNG</link>
</member>
</simplelist>
</refsection>
<refsection>
<title>履歴</title>
<revhistory>
<revision>
<revnumber>5.4.0</revnumber>
<revremark>XMLモジュールが導入されました.</revremark>
</revision>
</revhistory>
</refsection>
</refentry>
|