我正在嘗試解決如何從具有相同名稱但不同屬性名稱的重復元素串列中提取 XML 元素值。
在這種情況下,在 DataWeave 2.0 中,您將如何'ABC'為具有屬性 name 的元素提取元素值 ( ) 'xxx.UDFCHAR10'?
<root>
<UserArea>
<PropertyList>
<Property>
<NameValue name="xxx.CreatedBy">Test 1</NameValue>
</Property>
<Property>
<NameValue name="xxx.EnteredBy">Test 2</NameValue>
</Property>
<Property>
<NameValue name="xxx.SafetyFlag">false</NameValue>
</Property>
<Property>
<NameValue name="xxx.DependFlag">true</NameValue>
</Property>
<Property>
<NameValue name="xxx.UDFCHAR10">ABC</NameValue>
</Property>
</PropertyList>
</UserArea>
</root>
謝謝
uj5u.com熱心網友回復:
使用多值選擇器將所有重復的實體放入一個陣列中,然后您可以使用具有它的元素上的屬性選擇器按屬性值進行過濾。此方法將回傳一個提取值的陣列,但是如果您知道將只有一個元素,您可以通過 index 提取它[0]。
請注意,您的描述并不準確,因為該屬性位于重復元素的子元素中。
%dw 2.0
output application/java
---
(payload.root.UserArea.PropertyList.*Property
filter ($.NameValue.@name == "xxx.UDFCHAR10")).NameValue
輸出:
[
"ABC"
]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/319263.html
