2012-11-19 118 views
0

我觉得有几个XPath表达式,如:自定义分割操作

loan:_applicant/base:_entity/person:_locations/base:SmartRefOfLocationeJDvviUx[base:_entity/contact:_category/base:_underlyingValue='Personal' and base:_entity/contact:_confirmedByResident/common:_isConfirmed/base:_underlyingValue='true' and base:_entity/base:_process/base:_entity/base:_id/base:_underlyingValue = /loan:Application/base:_process/base:_entity/base:_id/base:_underlyingValue]/base:_entity/base:_id/base:_underlyingValue 

我尝试使用/base:_entity部分这些表达式拆分为这样的分配器:

string[] stringSeparators = new string[] { "/base:_entity" }; 
string[] pathTokens = xPath.Split(stringSeparators, StringSplitOptions.None); 

但我需要防止分裂当/base:_entity介于[]个字符之间时。

我有可能产生以下字符串数组为我写了上面的示例表达式输出是:

"loan:_applicant" 
"/person:_locations/base:SmartRefOfLocationeJDvviUx 
[base:_entity/contact:_category/base:_underlyingValue='Personal' and base:_entity/contact:_confirmedByResident/common:_isConfirmed/base:_underlyingValue='true' and base:_entity/base:_process/base:_entity/base:_id/base:_underlyingValue = /loan:Application/base:_process/base:_entity/base:_id/base:_underlyingValue]" 
"/base:_id/base:_underlyingValue" 

你有什么建议吗?

回答

1

我会使用一些可爱的正则表达式,如(?<=^.*\][^\[]*|^[^\[\]]*)/base:_entity,然后使用Regex的方法Split。它使用积极的后视来检查左边的第一个支架是否是右边的支架']'或根本没有支架。

+0

感谢您的回答! – anilca