xpath - RIP TutorialXPath ロケーションパスは、 /...

38
xpath #xpath

Transcript of xpath - RIP TutorialXPath ロケーションパスは、 /...

Page 1: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

xpath

#xpath

Page 2: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

1

1: xpath 2

2

2

Examples 2

XML 2

2

3

HTML 3

Xpath 4

2: 5

5

5

Examples 5

5

5

6

3: 7

7

7

Examples 7

7

7

4: 9

9

9

9

Examples 9

9

9

5: 11

Page 3: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

11

Examples 11

11

11

12

12

12

12

6: 14

14

14

14

Examples 14

LightDeviceSensor 14

Light 14

15

16

17

7: 18

18

Examples 18

18

8: 19

Examples 19

19

19

9: 21

Examples 21

21

10: 23

Examples 23

23

Page 4: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

23

11: 24

24

24

24

Examples 24

24

25

25

25

26

26

12: 28

28

28

28

Examples 29

29

29

30

30

Parashurama 30

Parashurama 31

Parusharama 31

32

32

33

34

Page 5: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

You can share this PDF with anyone you feel could benefit from it, downloaded the latest version from: xpath

It is an unofficial and free xpath ebook created for educational purposes. All the content is extracted from Stack Overflow Documentation, which is written by many hardworking individuals at Stack Overflow. It is neither affiliated with Stack Overflow nor official xpath.

The content is released under Creative Commons BY-SA, and the list of contributors to each chapter are provided in the credits section at the end of this book. Images may be copyright of their respective owners unless otherwise specified. All trademarks and registered trademarks are the property of their respective company owners.

Use the content presented in this book at your own risk; it is not guaranteed to be correct nor accurate, please send your feedback and corrections to [email protected]

https://riptutorial.com/ja/home 1

Page 6: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

1: xpathをいめるXPathは、XMLのをうためのです。

これはXSLTでされ、XQueryのサブセットです。ライブラリはほとんどののプログラミングでもです。

XPathは、W3Cによってされたをつです。

XPath 1.0 XMLパスXPath、バージョン1.0•

XPath 2.0 XMLパスXPath2.02•

XPath 3.0 XMLパスXPath3.0•

バージョン

バージョン

1.0 1999-12-16

2.0 2007123

3.0 2014-04-08

3.1 W3C 2015-12-17

Examples

サンプルXMLなし

に、XPathのをするサンプルXMLをします。

<r> <e a="1"/> <f a="2" b="1">Text 1</f> <f/> <g> <i c="2">Text 2</i> Text 3 <j>Text 4</j> </g> </r>

テキストを

サンプルXMLなし

https://riptutorial.com/ja/home 2

Page 7: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

このXPath、

/r/f/text()

このをつテキストノードをします

"Text 1"

そして、このXPath、

string(/r/f)

fのをします。

"Text 1"

をする

サンプルXMLなし

このXPath、

/r/e

このをします

<e a="1"/>

なHTML

HTML DOMが

<html> <body> <a>link</a> <div class='container' id='divone'> <p class='common' id='enclosedone'>Element One</p> <p class='common' id='enclosedtwo'>Element Two</p> </div> </body> </html>

のIDをつをページでする

//*[@id='divone'] # Returns <div class='container' id='divone'>

のパスののIDをつをつける

https://riptutorial.com/ja/home 3

Page 8: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

/html/body/div/p[@id='enclosedone'] # Returns <p class='common' id='enclosedone'>Element One</p>

のIDとクラスをつをする

//p[@id='enclosedone' and @class='common'] # Returns <p class='common' id='enclosedone'>Element One</p>

ののテキストをする

//*[@id='enclosedone']/text() # Returns Element One

ブラウザコンソールでのXpathのテスト

xpathをテストするなは、ブラウザのツールコンソールにあります。

フォーマットは

$x('//insert xpath here')

$ - セレクタであることをします。

x - xpathsをしていることをします。

$x("//button[text() ='Submit']")

このコマンドがされると、Submitとしいテキストのボタンであるのすべてのをします。

オンラインでxpathをいめるをむ https://riptutorial.com/ja/xpath/topic/883/xpathをいめる

https://riptutorial.com/ja/home 4

Page 9: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

2: ノードがするかどうかをするブールpath_to_node•

ブールにはのがあります

がであるかどうかをする1. がではないかNaN、0かどうかをチェックする2.

Examples

にはがありますか

XML

<Animal> <legs>4</legs> <eyes>2</eyes> <horns>2</horns> <tail>1</tail> </Animal>

XPATH

boolean(/Animal/tusks)

false

はをっていますか

XPATH

<Animal> <legs>4</legs> <eyes>2</eyes> <horns>2</horns> <tail>1</tail> </Animal>

XPATH

boolean(/Animal/horns)

true

https://riptutorial.com/ja/home 5

Page 10: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

にはがありますか

XML

<House> <LivingRoom> <plant name="rose"/> </LivingRoom> <TerraceGarden> <plant name="passion fruit"/> <plant name="lily"/> <plant name="golden duranta"/> </TerraceGarden> </House>

XPATH

boolean(/House//plant)

true

オンラインでノードがするかどうかをするをむ https://riptutorial.com/ja/xpath/topic/7432/ノードがするかどうかをする

https://riptutorial.com/ja/home 6

Page 11: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

3: ノードのテキストがであるかどうかをチェックする

ブールpath_to_node / text•stringpath_to_node= ''•

ブールにはのがあります

ノードがするかどうかをする1. がではないかNaN、0かどうかをチェックする2.

は、ノードのをすためにされます。

Examples

デボラにマスターがあり、そのテキストがでないかどうかをチェックする

XML

<Deborah> <address>Dark world</address> <master>Babadi</master> <ID>#0</ID> <colour>red</colour> <side>evil</side> </Deborah>

XPATH

boolean(/Deborah/master/text())

または

string(/Deborah/master) != ''

true

ドビーにマスターがあり、テキストがでないことをする

XML

<Dobby> <address>Hogwartz</address> <master></master> <colour>wheatish</colour>

https://riptutorial.com/ja/home 7

Page 12: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

<side>all good</side> </Dobby>

XPATH

boolean(/Dobby/master/text())

または

string(/Dobby/master) != ''

false

オンラインでノードのテキストがであるかどうかをチェックするをむ

https://riptutorial.com/ja/xpath/topic/7445/ノードのテキストがであるかどうかをチェックする

https://riptutorial.com/ja/home 8

Page 13: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

4: ノードのをするカウントノード•

パラメーター

カウント ノードセットのノードの

これをのとのみわせでして、ニーズにわせることができます。

Examples

にはのがいますか

XML

<Goku> <child name="Gohan"/> <child name="Goten"/> </Goku>

XPATH

count(/Goku/child)

2.0

にはいくつのがありますか

XML

<House> <LivingRoom> <plant name="rose"/> </LivingRoom> <TerraceGarden> <plant name="passion fruit"/> <plant name="lily"/> <plant name="golden duranta"/> </TerraceGarden> </House>

XPATH

https://riptutorial.com/ja/home 9

Page 15: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

5: ロケーションパスとXPath ロケーションパスは、 / characterでられたのロケーションステップです 。

step1/step2/step3

ロケーション・ステップには、 、 ノード・テスト 、およびオプションのリストがまれています 。 とノードテストは 、つのコロンによってされている:: 。 はカッコでまれています。

axis::nodeTest[predicate1][predicate2]

ロケーションパスのは、のコンテキストによってえられるコンテキストノードをむノードセットからまり、ロケーションパスが/まるはルートノードからまります。ステップで、のノードのノードNは、

えられたにって Nからすることができ、•

ノードテストとし、•すべてのにします。•

ロケーションパスのは、すべてのロケーションステップをしたにられたノードセットです 。

Examples

をトラバースする

childをしてルートノードからにする

/child::html/child::body/child::div/child::span

childがデフォルトのであるため、これはです

/html/body/div/span

すべてのをトラバースする

descendantおよびdescendant-or-selfは、のさのノードのすべてのをつけるためにできます。これとはに、 childにのみのをします。

/child::html/descendant::span /child::html/descendant-or-self::*

ダブルスラッシュ//ショートカットです/descendant-or-self::node()/ 。したがって、のはです。

https://riptutorial.com/ja/home 11

Page 16: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

table//td child::table/descendant-or-self::node()/child::td child::table/descendant::td table/descendant::td

をする

parentには、ノードのだけがまれます。のは、 bodyをしてhtmlをします。

/child::html/child::body/parent::html

..はparent::node()ショートカット..

ancestorとancestor-or-selfは、ノードのすべてのをします。のは、コンテキストノードのであるすべてのdivをします。

ancestor::div

「」

selfには、コンテキストノードだけがまれます。. self::node()ショートカットであり、にコンテキストノードにします。 .ショートカットはコンテキストノードのをするのにです。のはです。

.//span self::node()/descendant-or-self::node()/child::span descendant::span

selfは、XPath 1.0でちます。たとえば、コンテキストノードのすべてのh1 、 h2 、およびh3をするには、のようにします。

*[self::h1 or self::h2 or self::h3]

ノードとノードをする

following-siblingおよびpreceding-siblingには、コンテキストノードのにあるがまれ、 followingおよびprecedingには、コンテキストノードのにあるドキュメントのすべてのノードがまれますが、

これらののいずれもまたはノードをんでいません。•followingにはがまれていません。•precedingにははまれていません。•

following::span[1] following-sibling::*[last()]

およびノードのトラバース

https://riptutorial.com/ja/home 12

Page 18: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

6: がいくつかのをむ、またはむのノードをするのノードの

{パスへのパス} / name= '']

1.

ドキュメントのどこにでも

// * [name= '']

2.

パラメーター

ローカル なしのノードの

local-nameにはプレフィックスlookup nameXPATHがまれていません。

Examples

がLight、Device、またはSensorのノードをする

XML

<Galaxy> <Light>sun</Light> <Device>satellite</Device> <Sensor>human</Sensor> <Name>Milky Way</Name> </Galaxy>

XPATH

/Galaxy/*[local-name()='Light' or local-name()='Device' or local-name()='Sensor']

または

//*[local-name()='Light' or local-name()='Device' or local-name()='Sensor']

<Light>sun</Light> <Device>satellite</Device> <Sensor>human</Sensor>

Lightをむのノードをする

https://riptutorial.com/ja/home 14

Page 19: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

XML

<Data> <BioLight> <name>Firefly</name> <model>Insect</model> </BioLight> <ArtificialLight> <name>Fire</name> <model>Natural element</model> <source>flint</source> </ArtificialLight> <SolarLight> <name>Sun</name> <model>Star</model> <source>helium</source> </SolarLight> </Data>

XPATH

/Data/*[contains(local-name(),"Light")]

または

//*[contains(local-name(),"Light")]

<BioLight> <name>Firefly</name> <model>Insect</model> </BioLight> <ArtificialLight> <name>Fire</name> <model>Natural element</model> <source>flint</source> </ArtificialLight> <SolarLight> <name>Sun</name> <model>Star</model> <source>helium</source> </SolarLight>

スターでまるのノードをする

XML

<College> <FootBall> <Members>20</Members> <Coach>Archie Theron</Coach> <Name>Wild cats</Name> <StarFootballer>David Perry</StarFootballer> </FootBall> <Academics> <Members>100</Members>

https://riptutorial.com/ja/home 15

Page 20: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

<Teacher>Tim Jose</Teacher> <Class>VII</Class> <StarPerformer>Lindsay Rowen</StarPerformer> </Academics> </College>

XPATH

/College/*/*[starts-with(local-name(),"Star")]

または

//*[starts-with(local-name(),"Star")]

<StarFootballer>David Perry</StarFootballer> <StarPerformer>Lindsay Rowen</StarPerformer>

ボールでわるのノードをする

XML

<College> <FootBall> <Members>20</Members> <Coach>Archie Theron</Coach> <Name>Wild cats</Name> <StarPlayer>David Perry</StarPlayer> </FootBall> <VolleyBall> <Members>24</Members> <Coach>Tim Jose</Coach> <Name>Avengers</Name> <StarPlayer>Lindsay Rowen</StarPlayer> </VolleyBall> <FoosBall> <Members>22</Members> <Coach>Rahul Mehra</Coach> <Name>Playerz</Name> <StarPlayer>Amanda Ren</StarPlayer> </FoosBall> </College>

XPATH

/College/*[ends-with(local-name(),"Ball")]

または

//*[ends-with(local-name(),"Ball")]

<FootBall>

https://riptutorial.com/ja/home 16

Page 21: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

<Members>20</Members> <Coach>Archie Theron</Coach> <Name>Wild cats</Name> <StarPlayer>David Perry</StarPlayer> </FootBall> <VolleyBall> <Members>24</Members> <Coach>Tim Jose</Coach> <Name>Avengers</Name> <StarPlayer>Lindsay Rowen</StarPlayer> </VolleyBall> <FoosBall> <Members>22</Members> <Coach>Rahul Mehra</Coach> <Name>Playerz</Name> <StarPlayer>Amanda Ren</StarPlayer> </FoosBall>

のついたノードをするとをしない

XML

<Galaxy> <Light>sun</Light> <Device>satellite</Device> <Sensor>human</Sensor> <Name>Milky Way</Name> </Galaxy>

XPATH

/Galaxy/*[lower-case(local-name())="light"]

または

//*[lower-case(local-name())="light"]

<Light>sun</Light>

オンラインでがいくつかのをむ、またはむのノードをするをむ

https://riptutorial.com/ja/xpath/topic/3095/がいくつかのをむ-またはむのノードをする

https://riptutorial.com/ja/home 17

Page 22: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

7:

XPath 1.0には、デフォルトのというはありません。

また、のXMLでされているはXPathにをえません。はにXPathプロバイダにするがあります。そうしないと、はXPathではまったくできません。

Examples

<root xmlns="http://test/"> <element xmlns:example="http://foobar/"> <example:hello_world attribute="another example" /> </element> </root>

/rootとばれるくがしないため、もさないだろうrootドキュメントのルートレベルでは。ただし、の<root xmlns="http://test/">は<root xmlns="http://test/">をします。

/*[namespace-uri() = 'http://test/' and local-name() = 'root']

オンラインでをむ https://riptutorial.com/ja/xpath/topic/2324/

https://riptutorial.com/ja/home 18

Page 23: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

8: にづいてノードをする

Examples

カウントにづいてノードをする

サンプルXML

<Students> <Student> <Name> <First>Ashley</First> <Last>Smith</Last> </Name> <Grades> <Exam1>A</Exam1> <Exam2>B</Exam2> <Final>A</Final> </Grades> </Student> <Student> <Name> <First>Bill</First> <Last>Edwards</Last> </Name> <Grades> <Exam1>A</Exam1> </Grades> </Student> </Students>

XPath

なくとも2つのをしたすべてのをする

//Student[count(./Grades/*) > 1]

<Student> <Name> <First>Ashley</First> <Last>Smith</Last> </Name> <Grades> <Exam1>A</Exam1> <Exam2>B</Exam2> <Final>A</Final> </Grades> </Student>

のノードにづいてノードをする

https://riptutorial.com/ja/home 19

Page 24: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

サンプルXML

<Students> <Student> <Name> <First>Ashley</First> <Last>Smith</Last> </Name> <Grades> <Exam1>A</Exam1> <Exam2>B</Exam2> <Final>A</Final> </Grades> </Student> <Student> <Name> <First>Bill</First> <Last>Edwards</Last> </Name> <Grades> <Exam1>A</Exam1> </Grades> </Student> </Students>

XPath

Exam2のスコアがされているすべてのを

//Student[./Grades/Exam2]

または

//Student[.//Exam2]

<Student> <Name> <First>Ashley</First> <Last>Smith</Last> </Name> <Grades> <Exam1>A</Exam1> <Exam2>B</Exam2> <Final>A</Final> </Grades> </Student>

オンラインでにづいてノードをするをむ https://riptutorial.com/ja/xpath/topic/6504/にづいてノードをする

https://riptutorial.com/ja/home 20

Page 25: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

9: のテキストをむの

Examples

のテキストをむすべてのをする

のXMLをしてみてください。

<root> <element>hello</element> <another> hello </another> <example>Hello, <nested> I am an example </nested>.</example> </root>

のXPathはのとおりです。

//*[text() = 'hello']

<element>hello</element>をしますが、 <another>はしません。これは、 <another>にhelloテキストをむがまれているためです。

<element>と<another>をするには、 <element>できます。

//*[normalize-space(text()) = 'hello']

または

//*[normalize-space() = 'hello']

これはをうにのをトリムします。ここでは、 normalize-spaceをしているときにtext()ノードがオプションであることがわかりtext() 。

のテキストをむをするには、 containsをしcontains 。のは<example>をします。

//example[contains(text(), 'Hello')]

の/テキストノードにまたがるテキストをするは、できます. text()わりに。 .のテキストコンテンツとそのをします。

//example[. = 'Hello, I am an example .']

のテキストノードをするには、のコマンドをします。

https://riptutorial.com/ja/home 21

Page 26: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

//example//text()

それはすでしょう

"こんにちは、 "•

"はです"•""•

また、のテキストコンテンツをよりにるために、stringをすることができます

string(//example[1])

あるいはに

string(//example)

こんにちは、はです。

は、ノードセットがstringようなにされた、XPath 1.0はそのノードセットののノードをドキュメントでてりをするため、はします。

そう

string(/root/*)

すだろう

こんにちは

オンラインでのテキストをむのをむ https://riptutorial.com/ja/xpath/topic/1903/のテキストをむの

https://riptutorial.com/ja/home 22

Page 27: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

10: のをむの

Examples

のをつすべてのをする

のXMLをしてみてください。

<root> <element foobar="hello_world" /> <element example="this is one!" /> </root>

/root/element[@foobar]

<element foobar="hello_world" />をします。

のをつすべてのをする

のXMLをしてみてください。

<root> <element foobar="hello_world" /> <element example="this is one!" /> </root>

のXPathはのとおりです。

/root/element[@foobar = 'hello_world']

<element foobar="hello_world" />をします。

もできます

/root/element[@foobar="hello_world"]

オンラインでのをむのをむ https://riptutorial.com/ja/xpath/topic/6488/のをむの

https://riptutorial.com/ja/home 23

Page 28: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

11: のをつノードをつけるのノードの

/ path to / element [@attribute_name]•1.

ドキュメントのどこにでも//*[@]•

2.

いくつかのをつのノードの/ path to / element [@ attribute_name = '']•/ pathへのパス/[@ attribute_name = ""]•

3.

らかのをつドキュメントのどこでも// * [@ attribute_name = '']•// * [@ attribute_name = ""]•

4.

パラメーター

セレクタ

@ する、ノードのをします

[@ attribute_name]をうと、になくをつノードをできます。

このセレクタは、たちのニーズにわせて、start-withとlowercaseなどのやのみわせのいずれかをできます。

Examples

のをつノードをつける

XML

<Galaxy> <name>Milky Way</name> <CelestialObject name="Earth" type="planet"/> <CelestialObject name="Sun" type="star"/> </Galaxy>

XPATH

/Galaxy/*[@name]

または

//*[@name]

https://riptutorial.com/ja/home 24

Page 29: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

<CelestialObject name="Earth" type="planet" /> <CelestialObject name="Sun" type="star" />

のをつノードをつける

XML

<Galaxy> <name>Milky Way</name> <CelestialObject name="Earth" type="planet"/> <CelestialObject name="Sun" type="star"/> </Galaxy>

XPATH

/Galaxy/*[@name='Sun']

または

//*[@name='Sun']

<CelestialObject name="Sun" type="star" />

のマッチングによるノードの

XML

<Galaxy> <name>Milky Way</name> <CelestialObject name="Earth" type="planet"/> <CelestialObject name="Sun" type="star"/> </Galaxy>

XPATH

/Galaxy/*[contains(@name,'Ear')]

または

//*[contains(@name,'Ear')]

のわりにをすることもできます。

/Galaxy/*[contains(@name, "Ear")]

<CelestialObject name="Earth" type="planet" />

https://riptutorial.com/ja/home 25

Page 30: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

のマッチングによるノードのをしない

XML

<Galaxy> <name>Milky Way</name> <CelestialObject name="Earth" type="planet"/> <CelestialObject name="Sun" type="star"/> </Galaxy>

XPATH

/Galaxy/*[contains(lower-case(@name),'ear')]

または

//*[contains(lower-case(@name),'ear')]

または、でんだをします。

//*[contains(lower-case(@name), "ear")]

<CelestialObject name="Earth" type="planet" />

ののにするでノードをつける

XML

<Galaxy> <name>Milky Way</name> <CelestialObject name="Earth" type="planet"/> <CelestialObject name="Sun" type="star"/> </Galaxy>

XPATH

/Galaxy/*[starts-with(lower-case(@name),'ear')]

または

//*[starts-with(lower-case(@name),'ear')]

<CelestialObject name="Earth" type="planet" />

ののわりにするでノードをつける

XML

https://riptutorial.com/ja/home 26

Page 31: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

<Galaxy> <name>Milky Way</name> <CelestialObject name="Earth" type="planet"/> <CelestialObject name="Sun" type="star"/> </Galaxy>

XPATH

/Galaxy/*[ends-with(lower-case(@type),'tar')]

または

//*[ends-with(lower-case(@type),'tar')]

<CelestialObject name="Sun" type="star" />

オンラインでのをつノードをつけるをむ https://riptutorial.com/ja/xpath/topic/3096/のをつノードをつける

https://riptutorial.com/ja/home 27

Page 32: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

12: のノードをにしたノードのノードのすべての

/ノードへのパス/ ancestor :: node•1.

ノードののノードへの/パス/ ancestor :: ancestor_name•

2.

ノードの/ノードへのパス/ parent :: node•

3.

ノードのにいて/ノードへのパス/ following-sibling :: node•

4.

ノードにくの/ノードへのパス/ following-sibling :: sibling_name•

5.

ノードのする/ノードへのパス/ preceding-sibling :: node•

6.

ノードにするの/ノードへのパス/ preceding-sibling :: sibling_name•

7.

ノードのすべてののノード/ノードへのパス/ child :: node•

8.

ノードのののノード/ノードへのパス/:: chid_name•

9.

ノードのすべての/ノードへのパス/ descendant :: node•

10.

ノードのすべてのの/ノードへのパス/:: descendant_name•

11.

パラメーター

する

すべてのノード

ノード

ノードにく

の ノードにする

のたち

ネストレベルになくすべての

これらのは、ニーズにわせてのとみわせてできます。

https://riptutorial.com/ja/home 28

Page 33: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

Examples

のをつける

XML

<GrandFather name="Bardock" gender="male" spouse="Gine"> <Dad name="Goku" gender="male" spouse="Chi Chi"> <Me name="Gohan" gender="male"/> <brother name="Goten" gender="male"/> </Dad> </GrandFather>

XPATH

//Me/ancestor::node()

<GrandFather name="Bardock" gender="male" spouse="Gine"> <Dad name="Goku" gender="male" spouse="Chi Chi"> <Me name="Gohan" gender="male" /> <brother name="Goten" gender="male" /> </Dad> </GrandFather> <Dad name="Goku" gender="male" spouse="Chi Chi"> <Me name="Gohan" gender="male" /> <brother name="Goten" gender="male" /> </Dad>

のをつける

XML

<GrandFather name="Bardock" gender="male" spouse="Gine"> <Dad name="Goku" gender="male" spouse="Chi Chi"> <Me name="Gohan" gender="male"/> <brother name="Goten" gender="male"/> </Dad> </GrandFather>

XPATH

//Me/ancestor::Dad

または

//Me/parent::node()

<Dad name="Goku" gender="male" spouse="Chi Chi"> <Me name="Gohan" gender="male" /> <brother name="Goten" gender="male" />

https://riptutorial.com/ja/home 29

Page 34: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

</Dad>

のをつける

XML

<GrandFather name="Bardock" gender="male" spouse="Gine"> <Dad name="Goku" gender="male" spouse="Chi Chi"> <Me name="Gohan" gender="male" /> <brother name="Goten" gender="male" /> </Dad> </GrandFather>

XPATH

//Me/ancestor::GrandFather

または

//Me/parent::node()/parent::node()

<GrandFather name="Bardock" gender="male" spouse="Gine"> <Dad name="Goku" gender="male" spouse="Chi Chi"> <Me name="Gohan" gender="male" /> <brother name="Goten" gender="male" /> </Dad> </GrandFather>

のをつける

XML

<GrandFather name="Bardock" gender="male" spouse="Gine"> <Dad name="Goku" gender="male" spouse="Chi Chi"> <brother name="Goten" gender="male" /> <Me name="Gohan" gender="male" /> <brother name="Goten" gender="male" /> </Dad> </GrandFather>

XPATH

//Me/following-sibling::brother

<brother name="Goten" gender="male" />

Parashuramaのにすべてのアバターをにれよう

XML

https://riptutorial.com/ja/home 30

Page 35: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

<Dashavatar> <Avatar name="Matsya"/> <Avatar name="Kurma"/> <Avatar name="Varaha"/> <Avatar name="Narasimha"/> <Avatar name="Vamana"/> <Avatar name="Balabhadra"/> <Avatar name="Parashurama"/> <Avatar name="Rama"/> <Avatar name="Krishna"/> <Avatar name="Kalki"/> </Dashavatar>

XPATH

//Avatar[@name='Parashurama']/preceding-sibling::node()

<Avatar name="Matsya"/> <Avatar name="Kurma"/> <Avatar name="Varaha"/> <Avatar name="Narasimha"/> <Avatar name="Vamana"/> <Avatar name="Balabhadra"/>

Parashuramaのにすべてのアバターをにれよう

XML

<Dashavatar> <Avatar name="Matsya"/> <Avatar name="Kurma"/> <Avatar name="Varaha"/> <Avatar name="Narasimha"/> <Avatar name="Vamana"/> <Avatar name="Balabhadra"/> <Avatar name="Parashurama"/> <Avatar name="Rama"/> <Avatar name="Krishna"/> <Avatar name="Kalki"/> </Dashavatar>

XPATH

//Avatar[@name='Parashurama']/following-sibling::node()

<Avatar name="Rama" /> <Avatar name="Krishna" /> <Avatar name="Kalki" />

のものをくすべてのアバターをするParusharama

XML

https://riptutorial.com/ja/home 31

Page 36: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

<Dashavatar> <Avatar name="Matsya"/> <Avatar name="Kurma"/> <Avatar name="Varaha"/> <Avatar name="Narasimha"/> <Avatar name="Vamana"/> <Avatar name="Balabhadra"/> <Avatar name="Parashurama"/> <Avatar name="Rama"/> <Avatar name="Krishna"/> <Avatar name="Kalki"/> </Dashavatar>

XPATH

//Avatar[@name='Parashurama']/following-sibling::Avatar | //Avatar[@name='Parashurama']/preceding-sibling::Avatar

<Avatar name="Matsya" /> <Avatar name="Kurma" /> <Avatar name="Varaha" /> <Avatar name="Narasimha" /> <Avatar name="Vamana" /> <Avatar name="Balabhadra" /> <Avatar name="Rama" /> <Avatar name="Krishna" /> <Avatar name="Kalki" />

ハウスのすべてのノードをする

XML

<House> <Rooms>10</Rooms> <People>4</People> <TVs>4</TVs> <Floors>2</Floors> </House>

XPATH

/House/child::node()

<Rooms>10</Rooms> <People>4</People> <TVs>4</TVs> <Floors>2</Floors>

ののすべてのののを

XML

https://riptutorial.com/ja/home 32

Page 37: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

<House> <numRooms>4</numRooms> <Room name="living"/> <Room name="master bedroom"/> <Room name="kids' bedroom"/> <Room name="kitchen"/> </House>

XPATH

/House/child::Room

または

/House/*[local-name()='Room']

<Room name="living" /> <Room name="master bedroom" /> <Room name="kids' bedroom" /> <Room name="kitchen" />

ハウスのすべてのをするポジションになく

XML

<House> <numRooms>4</numRooms> <Floor number="1"> <Room name="living"/> <Room name="kitchen"/> </Floor> <Floor number="2"> <Room name="master bedroom"/> <Room name="kids' bedroom"/> </Floor> </House>

XPATH

/House/descendant::Room

<Room name="living" /> <Room name="kitchen" /> <Room name="master bedroom" /> <Room name="kids' bedroom" />

オンラインでのノードをにしたノードのをむ https://riptutorial.com/ja/xpath/topic/6495/のノードをにしたノードの

https://riptutorial.com/ja/home 33

Page 38: xpath - RIP TutorialXPath ロケーションパスは、 / characterでられたのロケーションステップです 。step1/step2/step3 ロケーション・ステップには、

クレジット

S. No

Contributors

1 xpathをいめる Community, hielsnoppe, kjhughes, Vinay, Wolfgang Schindler

2ノードがするかどうかをする

suchitra nair

3ノードのテキストがであるかどうかをチェックする

suchitra nair

4 ノードのをする suchitra nair

5 ロケーションパスと nwellnhof

6がいくつかのをむ、またはむのノードをする

Dimitre Novatchev, suchitra nair

7 4444, Keith Hall

8にづいてノードをする

Matthew

9 のテキストをむの Keith Hall

10 のをむの Keith Hall

11のをつノードをつける

Keith Hall, miken32, suchitra nair

12のノードをにしたノードの

suchitra nair

https://riptutorial.com/ja/home 34