2013-02-27 33 views
0

我想捕獲Xpath表達式中的條件。例如,在如下面的表達式:使用正則表達式捕獲Xpath條件

loan:_applicant/base:_entity/person:_phones/base:SmartRefOfPhoneeJDvviUx[base:_entity/contact:_category/base:_underlyingValue='Personal' and base:_entity/contact:_isMobile/base:_underlyingValue!='true']/base:_entity 

我想趕上:

base:_entity/contact:_category/base:_underlyingValue='Personal' 

base:_entity/contact:_isMobile/base:_underlyingValue!='true' 

該示例中的操作者的Xpath可以

它是possi使用正則表達式來獲取條件?記號化()

+0

「條件」被稱爲謂詞。是否有可能獲得嵌套謂詞的XPath?例如:'/ foo [bar [2] ='baz']' – 2013-02-27 09:23:58

回答

1

Xpath的謂詞包圍用方括號,所以

string [email protected]"\[.*\]"; 
string predicate=Regex.Match(input, regex).Value;//assuming there is a match 
[email protected]"\s(and|or)\s"; 
string[] conditions=Regex.Split(predicate, regex); 
1

的XPath 2.0具有用於正則表達式匹配的功能,如火柴()中,將(),和。這些在XPath 1.0中不可用。