Lieven Cardoen
Lieven Cardoen

Reputation: 25969

XPath question multiple selects

var assets1 = data.SelectNodes("//asset[@id]=" + oldBinaryAssetId);
var assets2 = data.SelectNodes("//Asset[@id]=" + oldBinaryAssetId);

Is it possible to make 1 xpath query of the two above?

Upvotes: 1

Views: 232

Answers (1)

Tomalak
Tomalak

Reputation: 338376

Your XPath is wrong to be gin with. You probably mean:

data.SelectNodes("//Asset[@id = '" + oldBinaryAssetId + "']");

To combine both variants (upper- and lower-case), you could use:

data.SelectNodes("//*[(name() = 'Asset' or name() = 'asset') and @id = '" + oldBinaryAssetId + "']");

or

data.SelectNodes("(//Asset | //asset)[@id = '" + oldBinaryAssetId + "']");

If you have any way to avoid the // operator, I recommend doing so. Your queries will be faster when you do, though this might only be noticable with large input documents.

Upvotes: 4

Related Questions