首页 > 解决方案 > 使用 XPath 函数清除不必要的信息

问题描述

我们有来自 XML 同步的结果,如下所示:

<items>
  </item>
    <extension_attributes>
      <coaf type="string">{"additional_fields":{"attribute_id":"425","attribute_code":"last_4_digits","admin_label":"Last 4 Digits","label":"Last 4 Digits","email":"1","pdf":"0","value":"4321"},"which_warehouse":{"attribute_id":"426","attribute_code":"which_warehouse","admin_label":"Warehouse Location","label":"Which Warehouse (Assuming Available Stock)","email":"1","pdf":"0","value":"Either or"}}</coaf>
    </extension_attributes>
  </item>
</items>

我相信(并且已经问过,但他们也只回答了一个假设)我们正在使用 XPath 1.0

为了获得匹配并加载字段,我设置了:

/root/items/item/extension_attributes/coaf

在值字段中,我放置了类似简单翻译的内容,以确保正确找到所有内容:

translate(/root/items/item/extension_attributes/coaf, 'attribute_code{}"attribute_id','')

这显然会带来一个非常疯狂的结果(意料之中),例如:

nlfls::425,:ls4gs,mnll:Ls 4 Dgs,ll:Ls 4 Dgs,ml:1,pf:0,vl:4321,whhwhs::426,:whhwhs,mnll:Whs Ln,ll:Whh Whs (Assmng Avll Sk),ml:1,pf:0,vl:Eh 

所以我们确信我们在正确的地方,只是不确定如何攻击它。

我们尝试了替换,但不确定如何将替换命令组合在一起以消除额外信息,特别是因为我们正在使用的这个程序中的值字段(当前)限制为 100 个字符。因此,获取所有额外信息的冗长替换行可能会超过字符数。

什么是摆脱所有不必要信息并基本上只保留重要字段的最佳方法,例如只保留 label:title1 & value:value1 和 label:title2 & value:value2 ?

标签: xpath

解决方案


推荐阅读