XPath examples
XPath is a query language that is used for traversing through an XML document. It is used commonly to search particular elements or attributes with matching patterns.
The best way to understand the power of XPath is to use examples and practice. On the left panel you will find some examples and on the right panel you will find an input items.xml file and the result of an XPath execution.
Before starting a reminder on the difference between element and attribute in an xml file.
Input file
We will use this XML file as input:
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
XPath examples
1. The simplest XPath
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/
1
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Explanations
/
means root. So it will copy the input file.
2. Select the content of element Table
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/Table
1
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Explanations
Elements are accessible with the name of the element. XPath are case sensitive. This produce the same result as before because Table is the root elememnt.
3. Get the value of the attribute key of the element Table
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/Table/@key
1
xml
PRODUCTS
1
Explanations
Attributes are accessible with @
+ the name of the attribute
4. List all elements Item
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/Table/Items/Item
1
xml
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Explanations
Here we use an aboslute path. /
at the begining indicates it's an absolute path. If you are already familiar with xpath, you have heard that in this example you can also use the xpath //Item
as a quicker xpath. Even it's true, this is not a best practice and has really poor performances. Do not use this shortcut.
5. List all elements Identifier
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/Table/Items/Item/Identifier
1
xml
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
Explanations
If we want only the identifiers that match a condition, for example: where the key is ean, then we have to use predicates.
6. List all elements Identifier where attribute key
is EAN_13
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/Table/Items/Item/Identifier[@key='EAN_13']
1
xml
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="EAN_13">1234567890127</Identifier>
1
2
3
4
5
2
3
4
5
Explanations
[@key='EAN_13']
is called a predicate. Predicate refers to the XPath expression written in square brackets. It allows to refers some condition. If we want the values, we have to add a function at the end of the XPath, see the next example.
7. List all elements Identifier values where attribute key
is EAN_13
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/Table/Items/Item/Identifier[@key='EAN_13']/string()
1
xml
1234567890123
1234567890124
1234567890125
1234567890126
1234567890127
1
2
3
4
5
2
3
4
5
Explanations
string()
is a function to force the result to be a string.
8. Get the second Item
element
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/Table/Items/Item[2]
1
xml
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
Explanations
The first element is either 1
or first()
.
9. Get the last Item
element
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/Table/Items/Item[last()]
1
xml
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
1
2
3
4
5
2
3
4
5
Explanations
last()
and first()
can be used.
10. Get the three first Item
elements
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/Table/Items/Item[position() <= 3]
1
xml
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Explanations
When you will use XSLT you will have to replace <
by <
and >
by >
. This because they are reserved characters in XSLT. Trick to remember: lt = less than, gt = greater than.
11.Get all elements Item
where attribute partition
is ACTIVES
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/Table/Items/Item[@partition='ACTIVES']
1
xml
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Explanations
The XPath in the bracket is relative to the element before the bracket. So the predicate here applies to Item.
12. Get all elements Item
where element Classification
TYPOLOGY is PHONES
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/Table/Items/Item[Classification[@key='TYPOLOGY']='PHONES']
1
xml
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Explanations
Predicates can be imbricates.
13. Get all elements Item
where attribute partition
is ACTIVES and where element Classification
TYPOLOGY is PHONES
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/Table/Items/Item[@partition='ACTIVES' and Classification[@key='TYPOLOGY']='PHONES']
1
xml
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Explanations
You can use multiple conditions using and
and or
.
14. Get all TITLE_EN values for elements Item
where attribute partition
is ACTIVES and where element Classification
TYPOLOGY is PHONES
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/Table/Items/Item[@partition='ACTIVES' and Classification[@key='TYPOLOGY']='PHONES']/Field[@key='TITLE_EN']/string()
1
xml
PRODUCTS
1
Explanations
Take a minute to really understand this XPath. Remember predicates are like filters on elements.
Best practice
To build an XPath, first start with the path of elements or attributs that has to be displayed, then add the predicates. In the example above you should set /Table/Items/Item/Field/string()
and then add the predicates.
15. Get all elements Item
where there is no element Classification
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/Table/Items/Item[not(Classification)]
1
xml
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
1
2
3
4
5
2
3
4
5
Explanations
The not(input_parameter)
function return false if the input parameter is true, false otherwise.
16. Count all elements Item
where there is no element Classification
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
count(/Table/Items/Item[not(Classification)])
1
xml
1
1
Explanations
The count()
function allows to count elements.
17. Get all sub-elements
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/Table/Items/Item[1]/*
1
xml
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
1
2
3
4
5
6
2
3
4
5
6
Explanations
The *
means all sub elements. If you need all attributes, use @*
18. Get all the sub-elements whose name is not equal to Identifier
Click on the result tab to view the result
xml
<Table key="PRODUCTS">
<Items>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890123</Identifier>
<Identifier key="SKU">PH-001</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890124</Identifier>
<Identifier key="SKU">PH-002</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 2</Field>
<Field key="DESCRIPTION_EN">The other new phone</Field>
<Field key="PRICE_EURO">759</Field>
</Item>
<Item partition="ARCHIVED">
<Identifier key="EAN_13">1234567890125</Identifier>
<Identifier key="SKU">PH-003</Identifier>
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 3</Field>
<Field key="DESCRIPTION_EN">An old phone</Field>
<Field key="PRICE_EURO">389.9</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890126</Identifier>
<Identifier key="SKU">DI-001</Identifier>
<Classification key="TYPOLOGY">DISHWASHERS</Classification>
<Field key="TITLE_EN">Dishwasher 1</Field>
<Field key="DESCRIPTION_EN">The new dishwasher</Field>
<Field key="PRICE_EURO">1240.3</Field>
</Item>
<Item partition="ACTIVES">
<Identifier key="EAN_13">1234567890127</Identifier>
<Identifier key="SKU">WA-001</Identifier>
<Field key="TITLE_EN">Watch 1</Field>
</Item>
</Items>
</Table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/Table/Items/Item[1]/*[name()!='Identifier']
1
xml
<Classification key="TYPOLOGY">PHONES</Classification>
<Field key="TITLE_EN">Phone 1</Field>
<Field key="DESCRIPTION_EN">The new phone</Field>
<Field key="PRICE_EURO">999.99</Field>
1
2
3
4
2
3
4
Explanations
name()
referes to the name of the element (or the name of the attribute).
What you have learned
- XPath is a very powerfull tool to access data in an XML file.
- Filters are done with predicates.
- Functions can be used in predicates for complex filters.