Describe the properties of the different XML objects
The nodes and their properties can be accessed and modified.
A XML Document has two properties: root and url
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);
A XML Element has seven properties:
doc = `xmlReadStr`_("<root xmlns:bar=""http://www.scilab.org/""><bar:a att=""foo"" rib=""bar""><b>Hello</b><c> world</c></bar:a></root>");
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);
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.
doc = `xmlReadStr`_("<root xmlns:bar=""http://www.scilab.org/""><bar:a att=""foo"" rib=""bar""><b>Hello</b><c> world</c></bar:a></root>");
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);
A XML Namespace has two properties: href and prefix
doc = `xmlReadStr`_("<root xmlns:bar=""http://www.scilab.org/""><bar:a att=""foo"" rib=""bar""><b>Hello</b><c> world</c></bar:a></root>");
ns = doc.root.children(1).namespace;
ns.href
ns.prefix
xmlDelete(doc);
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.
The size of the list can be retrieved in using ‘size’ field.
The name or the contents of each node of the list can be retrieved in using ‘name’ or ‘content’ field.
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);
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.
The size of the set can be retrieved with field ‘size’.
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);
A XML Validation file is an object used to validate a document. It is possible to validate in using DTD, Relax NG or schema.
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");
Version Description 5.4.0 XML module introduced. .. _XML Document: XMLObjects.html#XMLDocument .. _xmlNs: xmlNs.html .. _XML Attributes: XMLObjects.html#XMLAttributes .. _XML Element: XMLObjects.html#XMLElement .. _xmlRead: xmlRead.html .. _xmlSchema: xmlSchema.html .. _XML XPath result set: XMLObjects.html#XMLNodeSet .. _XML Node List: XMLObjects.html#XMLNodeList .. _xmlRelaxNG: xmlRelaxNG.html .. _xmlReadStr: xmlReadStr.html .. _XML Namespace: XMLObjects.html#XMLNamespace .. _xmlDocument: xmlDocument.html .. _xmlDTD: xmlDTD.html .. _xmlElement: xmlElement.html .. _XML Validation file: XMLObjects.html#XMLValid