【问题标题】:Custom splitting operation自定义拆分操作
【发布时间】:2012-11-19 13:09:57
【问题描述】:

想想我有几个 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"

你有什么建议吗?

【问题讨论】:

    标签: c# string text xpath split


    【解决方案1】:

    我会使用一些可爱的正则表达式,例如(?<=^.*\][^\[]*|^[^\[\]]*)/base:_entity,然后使用正则表达式的方法拆分。它使用肯定的后视来检查左边的第一个括号是右括号']'还是根本没有括号。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多