I use CSharp, XPath and HTMLAgility Pack. I use XPath strings such as:
"//table[3]/td[1]/span[2]/text() | //table[6]/td[1]/span[2]/text()"
"//table[8]/td[1]/span[2]/text() | //table[10]/td[1]/span[2]/text()"
The difference is only in table numbers. Is it possible to use some other XPath function to replace the XPath or |?
What I actually do: With the first XPath string (where I have table numbers 3 & 6) I extract one value. With the second XPath string (where i have table numbers are 8 & 10) I extract another value.
And additional question about performance – is the XPath string //table[8]/td[1]/span[2]/text() faster than the XPath string with OR //table[8]/td[1]/span[2]/text() | //table[10]/td[1]/span[2]/text()? I ask this because I have many many XPath strings for many many values and if there is a difference which really means I need to try something else. I can’t do the measurement right now that’s why I ask you this question to share your experience.
Firstly,
//table[6]looks odd. Are you sure you don’t mean(//table)[6]? (The first selects every table that is the 6th child of its parent; the second selects the sixth table in the document.) I will assume the latter.In XPath 2.0 you can write
In 1.0 that would have to be
Or (in either release) you could write
Your question about performance can’t be answered without knowing what XPath implementation you are using.