是否可以缩小此XPath表达式

问题描述 投票:0回答:3

我不是XPath专家,我找不到执行此操作的工具。有没有办法缩小此XPath语句? 80%是多余的。

XPATH 2

(//CustomField | //fields)[
     (fullName[not(matches(text(), "chk_[a-zA-Z0-9]+__c"))] and type[text()="Checkbox"]) or
     (fullName[not(matches(text(), "txt_[a-zA-Z0-9]+__c"))] and type[text()="Text"]) or
     (fullName[not(matches(text(), "txa_[a-zA-Z0-9]+__c"))] and type[text()="Textarea"]) or
     (fullName[not(matches(text(), "txr_[a-zA-Z0-9]+__c"))] and type[text()="Richtext"]) or
     (fullName[not(matches(text(), "txl_[a-zA-Z0-9]+__c"))] and type[text()="LongTextArea"]) or
     (fullName[not(matches(text(), "num_[a-zA-Z0-9]+__c"))] and type[text()="Number"]) or
     (fullName[not(matches(text(), "dat_[a-zA-Z0-9]+__c"))] and type[text()="Date"]) or
     (fullName[not(matches(text(), "lkp_[a-zA-Z0-9]+__c"))] and type[text()="Lookup"]) or
     (fullName[not(matches(text(), "mdr_[a-zA-Z0-9]+__c"))] and type[text()="MasterDetail"]) or
     (fullName[not(matches(text(), "dtm_[a-zA-Z0-9]+__c"))] and type[text()="DateTime"]) or
     (fullName[not(matches(text(), "url_[a-zA-Z0-9]+__c"))] and type[text()="Url"]) or
     (fullName[not(matches(text(), "pkl_[a-zA-Z0-9]+__c"))] and type[text()="Picklist"]) or
     (fullName[not(matches(text(), "pkm_[a-zA-Z0-9]+__c"))] and type[text()="MultiselectPicklist"]) or
     (fullName[not(matches(text(), "cur_[a-zA-Z0-9]+__c"))] and type[text()="Currency"]) or
     (fullName[not(matches(text(), "pct_[a-zA-Z0-9]+__c"))] and type[text()="Percent"]) or
     (fullName[not(matches(text(), "fcur_[a-zA-Z0-9]+__c"))] and type[text()="Currency"] and formula) or
     (fullName[not(matches(text(), "rcnt_[a-zA-Z0-9]+__c"))] and type[text()="Summary"] and summaryOperation[text()="count"]) 
]

这是具有一个匹配项的XML文档的精简版本

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">

    <fields>
        <fullName>txl_Description__c</fullName>
        <deprecated>false</deprecated>
        <externalId>false</externalId>
        <label>Price Schedule Description</label>
        <length>4000</length>
        <trackHistory>false</trackHistory>
        <trackTrending>false</trackTrending>
        <type>LongTextArea</type>
        <visibleLines>5</visibleLines>
    </fields>
    <fields>
        <fullName>Reason_For_Override__c</fullName>
        <deprecated>false</deprecated>
        <externalId>false</externalId>
        <label>Reason for Override</label>
        <length>1000</length>
        <trackHistory>false</trackHistory>
        <trackTrending>false</trackTrending>
        <type>LongTextArea</type>
        <visibleLines>2</visibleLines>
    </fields>
</CustomObject>
xpath xpath-2.0
3个回答
0
投票

我彻底检查了您的表情,看来冗余几乎为零。 _[a-zA-Z0-9]+__c部分与优化表达式的相关性较低。


0
投票
您可以用text()替换所有出现的.,无论如何都是更好的做法。
© www.soinside.com 2019 - 2024. All rights reserved.