开发者

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?


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜