summaryrefslogtreecommitdiff
path: root/modules/xml/help/en_US/XMLObjects.xml
blob: 2ee3f16f8c50cd85ad657182b33def932f03f62c (plain)
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
<?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="en">
    <refnamediv>
        <refname>XML Objects</refname>
        <refpurpose>Describe the properties of the different XML objects</refpurpose>
    </refnamediv>
    <refsection>
        <title>Contents</title>
        <itemizedlist>
            <listitem>
                <para>
                    <link linkend="XMLDocument">XML Document</link>
                </para>
            </listitem>
            <listitem>
                <para>
                    <link linkend="XMLElement">XML Element</link>
                </para>
            </listitem>
            <listitem>
                <para>
                    <link linkend="XMLAttributes">XML Attributes</link>
                </para>
            </listitem>
            <listitem>
                <para>
                    <link linkend="XMLNamespace">XML Namespace</link>
                </para>
            </listitem>
            <listitem>
                <para>
                    <link linkend="XMLNodeList">XML Node List</link>
                </para>
            </listitem>
            <listitem>
                <para>
                    <link linkend="XMLNodeSet">XML XPath result set</link>
                </para>
            </listitem>
            <listitem>
                <para>
                    <link linkend="XMLValid">XML Validation file</link>
                </para>
            </listitem>
        </itemizedlist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>The nodes and their properties can be accessed and modified.</para>
    </refsection>
    <refsection id="XMLDocument">
        <title>XML Document</title>
        <para>A XML Document has two properties: root and url
            <itemizedlist>
                <listitem>
                    <para>
                        <emphasis role="bold">root</emphasis>: the root element of the document, it is a XML Element;
                    </para>
                </listitem>
                <listitem>
                    <para>
                        <emphasis role="bold">url</emphasis>: the url, as a string, of the document if it exist or an empty string if it is undefined.
                    </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 Element</title>
        <para>A XML Element has seven properties:
            <itemizedlist>
                <listitem>
                    <para>
                        <emphasis role="bold">name</emphasis>: the tag name;
                    </para>
                </listitem>
                <listitem>
                    <para>
                        <emphasis role="bold">namespace</emphasis>: a XML Namespace object;
                    </para>
                </listitem>
                <listitem>
                    <para>
                        <emphasis role="bold">content</emphasis>: the node content as a string. For example, the content of the node A in &lt;A&gt;hello &lt;B&gt;world&lt;/B&gt; will be the string "hello world";
                    </para>
                </listitem>
                <listitem>
                    <para>
                        <emphasis role="bold">type</emphasis>: the type of the node as a string. It can be on of the following values: "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>: the parent XML Element;
                    </para>
                </listitem>
                <listitem>
                    <para>
                        <emphasis role="bold">attributes</emphasis>: the node attributes as a XML Attributes object;
                    </para>
                </listitem>
                <listitem>
                    <para>
                        <emphasis role="bold">children</emphasis>: the children elements as a XML Node List object.
                    </para>
                </listitem>
                <listitem>
                    <para>
                        <emphasis role="bold">line</emphasis>: the line definition of this XML Element.
                    </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);

    // Add a new attribute named "new_attribute"
    first.attributes.new_attribute = "value";

    // Display the first child namespace
    first.namespace

    // Display the node content
    first.content

    // b has a parent
    b.parent

    // You can add a new child to first
    first.children(3) = b

    // non-integer index can be used to make insertion
    first.children(1.5) = "<d> Scilab</d>"

    // First child has been defined at line...
    b.line

    xmlDump(first)
    xmlDelete(doc);
    ]]></programlisting>
        </para>
    </refsection>
    <refsection id="XMLAttributes">
        <title>XML Attributes</title>
        <para>A XML Attributes is a kind of hashtable which maps attributes name to attributes value. An attribute value can be accessed or modified in using the attribute name as field of this object or in using an index between 1 and attributes size.</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);

    // Read an attribute
    first.attributes.att

    // Set an empty attribute
    first.attributes.att = "";

    // Add a new attribute
    first.attributes.hello = "world";

    // Use an index
    first.attributes(1) = "Bonjour";
    first.attributes(1)

    xmlDump(first)
    xmlDelete(doc);
    ]]></programlisting>
    </refsection>
    <refsection id="XMLNamespace">
        <title>XML Namespace</title>
        <para>A XML Namespace has two properties: href and prefix
            <itemizedlist>
                <listitem>
                    <para>
                        <emphasis role="bold">href</emphasis>: the namespace href as a string;
                    </para>
                </listitem>
                <listitem>
                    <para>
                        <emphasis role="bold">prefix</emphasis>: the prefix to use for this namespace, as a string.
                    </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 Node List</title>
        <para>A XML Node List is a type used to enumerate the children of an element. Each element can be accessed with an integer index. Since this is a list, it is possible to make insertion of new element in it, in using double index.</para>
        <para>The size of the list can be retrieved in using 'size' field.</para>
        <para>The name or the contents of each node of the list can be retrieved in using 'name' or 'content' field.</para>
        <programlisting role="example"><![CDATA[
    doc = xmlReadStr("<root><a>Hello</a><b> world</b></root>");
    c = doc.root.children;

    // We check that we have two elements
    c.size

    // Read the first element
    xmlDump(c(1))

    // Replace an element by another one
    c(1) = "<c>Hello</c>"

    // Insert a new element between the first and the second
    c(1.5) = "<d> Scilab</d>" // 1.5 or 1.234...

    // Insert a new element at the tail or at the head of the list
    c(0) = "<e>Head </e>"
    c(217) = "<f> Tail</f>"

    xmlDump(c)

    // Get the nodes name
    c.name

    // Get the nodes contents
    c.content

    xmlDelete(doc);
    ]]></programlisting>
    </refsection>
    <refsection id="XMLNodeSet">
        <title>XML XPath result set</title>
        <para>A XML Node Set is an object returned by a XPath query. It is not possible to insert new elements or to replace existing ones. It is just possible to get them in using an integer index.</para>
        <para>The size of the set can be retrieved with field '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

    // Or ...
    s.content

    xmlDelete(doc);
    ]]></programlisting>
    </refsection>
    <refsection id="XMLValid">
        <title>XML Validation file</title>
        <para>A XML Validation file is an object used to validate a document. It is possible to validate in using DTD, Relax NG or 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");

    // Validation
    xmlValidate(doc, dtd);
    xmlValidate(doc, rng);
    xmlValidate(doc, schema);

    xmlDelete("all");
    ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>See Also</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>History</title>
        <revhistory>
            <revision>
                <revnumber>5.4.0</revnumber>
                <revremark>XML module introduced.</revremark>
            </revision>
        </revhistory>
    </refsection>
</refentry>