xmlXPath
XML文書にXPathクエリを作成する
呼び出し手順
result = xmlXPath(xmlObj, queryStr [, namespaces])
引数
xmlObj
XMLDocまたはXMLElem型のXML mlist
queryStr
Xpathクエリ
namespaces
オプションの文字列の n x 2行列
result
XMLElementsの集合または数値または文字列または論理値
説明
特定の文書中またはある要素で始まるXPathクエリを作成します.
名前空間を使用する必要がある場合,オプション引数によりこれらを
定義する必要があります.
XML名前空間は最初のタグにキーワード "xmlns" で定義します.
XPathに関する詳細については, W3C recommandationを参照ください.
例
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 = ""+..
"Hello"
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 = ""+..
"HelloScilabWorldNothing"
doc = xmlReadStr(t);
e = doc.root.children(1);
// eの属性を取得
xp = xmlXPath(e, "@*");
xmlAsText(xp)
// eから'b'を取得
xp = xmlXPath(e, "b");
xmlAsText(xp)
xmlDelete(doc);
]]>
参照
W3C XPath recommandation
XPathチュートリアル
履歴
5.4.0
XML文字列が導入されました.