<< xmlNs XML Management xmlRead >>

Scilab Help >> XML Management > XML Objects

XML Objects

異なるのXMLオブジェクトのプロパティを記述する

内容

説明

ノードおよびそのプロパティをアクセスおよび修正可能です.

XML文書

XML文書は以下の2つのプロパティを有します: root および 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);

XML要素

XML要素は以下の7つのプロパティを有します:

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);

XML属性

XML属性は,属性の名前を属性の値にマップするハッシュテーブルの一種です. 属性の値は,このオブジェクトのフィールドとして属性の名前,または 1から属性の大きさまでの添字番号によりアクセスや修正が可能です.

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);

XML名前空間

XML名前空間は以下の2つのプロパティを有します: href および prefix

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);

XMLノードリスト

XMLノードリストはある要素の子に番号を付ける際に使用される 型です.各要素は整数の添字によりアクセスできます. これはリストであるため,doubleの添字により, 新しい要素をこのリストに挿入することができます.

リストの大きさは,'size'フィールドにより取得できます.

リストの各ノードの名前または内容は'name'または'content'フィールド により取得できます.

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);

XML XPath結果セット

XMLノードセットは,XPathクエリから返されたオブジェクトです. 新しい要素を挿入したり,既存の要素を置換することはできません. できることは整数の添字により要素を取得することのみです.

このセットの大きさは'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
// または ...
s.content
xmlDelete(doc);

XML検証ファイル

XML検証ファイルは文書の検証に使用されるオブジェクトです. DTD, Relax NGまたは 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");
// 検証
xmlValidate(doc, dtd);
xmlValidate(doc, rng);
xmlValidate(doc, schema);
xmlDelete("all");

参照

履歴

VersionDescription
5.4.0 XMLモジュールが導入されました.

Report an issue
<< xmlNs XML Management xmlRead >>