Bookmark and Share

XPath - Vertical Bar | (Pipe)

XPath makes use of the character "|", which we will be referring to as pipe from here on out. The pipe character is a way of combining two or more expressions into one. Depending on where you are using XPath, this ability to combine multiple expressions into one may be useful.

Advertise on

This lesson will teach you how to use XPath's combine feature, "|".

We will be using our lemonade2.xml file, which you can download.

XML Code, lemonade2.xml:

		<lemonade supplier="mother" id="1">
		<pop supplier="store" id="2">

		<chips supplier="store" id="3">


XPath - Combining Two Expressions with |

When you need to select multiple things with one expression, chances are you will have to use the pipe character. In our lemonade2.xml document, we might want to select the children of chips and the children of pop. To do this, we would use the pipe character "|".

Combining XPath Expression:

inventory/snack/chips/* | inventory/drink/pop/*

This expression combines two expressions into one and will select every element that matches either expression.

XPath - Combining Multiple Expressions with |

Although you probably won't use this feature very often, it is possible to combine as many expressions as you want with the pipe character. Here is an example that selects all of the children elements of chips, using |.

Combining XPath Expression:

chips/price | chips/amount | chips/calories
Bookmark and Share

Download's XML Book

If you would rather download the PDF of this tutorial, check out our XML eBook from the store.

Found Something Wrong in this Lesson?

Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time!

Advertise Here

More Tutorials!
Microsoft Office Tutorials Artist Tutorials