开发者

XPath question multiple selects

开发者 https://www.devze.com 2022-12-13 10:19 出处:网络
var assets1 = data.SelectNodes(\"//asset[@id]=\" + oldBinaryAssetId); var assets2 = 开发者_运维百科data.SelectNodes(\"//Asset[@id]=\" + oldBinaryAssetId);
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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消