ユーザ用ツール

サイト用ツール


xml:xpath

XML - XPath

ノードセット関数

position

ノードのインデックス番号を返す

Example

Elementノード内の1番目のChildノードを返す

//Element/Child[position()=1]

last

最後のノードのposition値を返す

Example

Elementノード内の最後の子要素ノードを返す

/Element/*[position()=last()]"

count

ノード数を返す

Example

子要素が無いElementノードを返す

//Element[count(./*)=0]

name

タグ名を返す

Example

タグ名がPriceのノードを返す

//*[name()='Price']"

文字列関数

string

文字列値を返す

Example

number属性の値が1のノードを返す

//*[string(@number)='1']"

contains

指定した文字列を含む要素を返す

Example

name属性の値にaを含むElementノードを返す

//Element[contains(@name,'a')]

start-width

指定した文字列ではじまる要素を返す

Example1

Elementの値がcontentsではじまるElementノードを返す

//Element[starts-with(.,'contents')]

Example2

エレメント名がtext1_ではじまるノードを返す

//*[starts-with(name(),'text1_')]

Example3

name属性の値がsection1ではじまるElementノードを返す

//Element[starts-with(@name,'section1')]

Example4

name属性の値がsection1かsection2ではじまるElementノードを返す

//Element[starts-with(@name,'section1') or starts-with(@name,'section2')]

normalize-space

要素内のテキストを空白/改行を取り除いて返す

Example

idが1の要素内のテキストを空白/改行を取り除いて返す

normalize-space(id('1'))

string-length

要素内のテキスト長を返す

Example1

idが1の要素内のテキスト長を返す

string-length(id('1'))

Example2

空白/改行以外のテキストを100文字以上含むElementノードを返す

//Element[string-length(normalize-space()) > 100]

xml/xpath.txt · 最終更新: 2018/06/25 09:41 by 127.0.0.1