Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.0.1 - 日本語

Change language to:
English - Français - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Scilabヘルプ >> XML Management > xmlXPath

xmlXPath

XML文書にXPathクエリを作成する

呼び出し手順

result = xmlXPath(xmlObj, queryStr)
result = xmlXPath(xmlObj, queryStr, namespaces)

引数

xmlObj

XMLDocまたはXMLElem型のXML mlist

queryStr

Xpathクエリ

namespaces

オプションの文字列の n x 2行列

result

XMLElementsの集合または数値または文字列または論理値

説明

特定の文書中またはある要素で始まるXPathクエリを作成します. 名前空間を使用する必要がある場合,オプション引数によりこれらを 定義する必要があります. XML名前空間は最初のタグにキーワード "xmlns" で定義します.

XPathに関する詳細については, W3C recommandationを参照ください.

doc = xmlRead("http://www.w3.org/TR/2009/REC-xml-names-20091208/xml-names-10-3e.xml");

// "note"に名前が等しいノードを取得
xp = xmlXPath(doc, "//note");
s = size(xp);
for i=1:s(2)
    xmlDump(xp(i))
end

// 名前が"note"に等しいノードの数を数える
xp = xmlXPath(doc, "count(//note)")

// id="Philosophy"のノードを取得
xp = xmlXPath(doc, "//*[@id=""Philosophy""]");
s = size(xp);
if (s(2) <> 0) then
    xmlDump(xp(1))
end

// 属性番号が5に等しいノードを取得
xp = xmlXPath(doc, "//*[number(@num)=5]");
s = size(xp);
if (s(2) <> 0) then
    xmlDump(xp(1))
end

// 'emph'という名前のノードの全ての属性の名前と内容を取得
xp = xmlXPath(doc, "//emph/@*");
xp.name
xp.content
xmlDelete(doc);

// 名前空間を検索
t = "<root xmlns:scilab=""http://www.scilab.org"">"+..
    "<scilab:a att=""foo"" rib=""bar""><b>Hello</b></scilab:a></root>"
doc = xmlReadStr(t);

// aという名前の要素を探します
xmlXPath(doc, "//a") // => nothing
xmlXPath(doc, "//scilab:a", ["scilab" "http://www.scilab.org"]) // => OK

// このコードは失敗します:
// xmlXPath(doc, "//scilab:a") // => エラー
xmlDelete(doc);

// 要素で始まるクエリ
t = "<root att=""attribute""><a a1=""A1"" a2=""A2"" a3=""A3"">"+..
    "<b>Hello</b><c>Scilab</c><b>World</b></a><b>Nothing</b></root>"
doc = xmlReadStr(t);
e = doc.root.children(1);

// eの属性を取得
xp = xmlXPath(e, "@*");
xmlAsText(xp)

// eから'b'を取得
xp = xmlXPath(e, "b");
xmlAsText(xp)
xmlDelete(doc);

XMLコメントの取得:

doc = xmlRead(SCI+"/modules/ui_data/etc/newsfeed.xml");
c = xmlXPath(doc, "//comment()");   // do not forget the trailing ()
c.content'

xmlDelete(doc);
--> c.content'
 ans  =
! RSS Feed URL                                                        !
! automatic news change interval time (in ms), set to -1 to disable   !
! periodic feed update interval time (in ms), set to -1 to disable    !

履歴

VersionDescription
5.4.0 XML文字列が導入されました.
Report an issue
<< xmlWrite XML Management HDF5 Management >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Feb 12 23:12:41 CET 2018