2012-11-19 176 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