xpath - 使用 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 ?
解决方案
推荐阅读
- laravel - Laravel 5.6 验证 required_without 多个
- sql - SQL:连接两个表并从一个表中选择组中的前 N 个
- javascript - 通过在 2 个不同的 div 框中显示获取的 MySQL 数据来解决 JS 问题 [PHP、MySQL 和 JS]
- angular5 - 使用按钮如何滚动到角度 6 中的选定 div
- c# - 领域对象的创建
- google-apps-script - 无法从 Google 文档中清除页脚
- android - Android如何默认强制屏幕密度
- php - PHP 在 Unicode 字符串中查找一个单词
- php - Laravel:如何创建依赖于多个模型的资源
- python - 有没有办法触发 tkinter 中按钮的可点击性?