Example:
<Attributes>
<Map>
<entry key="Role_111">
<value>
<List>
<String>07771</String>
</List>
</value>
</entry>
<entry key="Role_13">
<value>
<List>
<String>07771</String>
</List>
</value>
</entry>
<entry key="Role_16">
<value>
<List>
<String>07770</String>
<String>07771</String>
</List>
</value>
</entry>
<entry key="Role_37">
<value>
<List>
<String>07771</String>
</List>
</value>
</entry>
<entry key="Role_5">
<value>
<List>
<String>07771</String>
</List>
</value>
</entry>
<entry key="isValid" value="true"/>
<entry key="usercode" value="001"/>
</Map>
</Attributes>
In this xml, I have extract value of all roles for the user and print them to get the key and value separately. They should be in separate column and diffrent row entry for each role.
I tried few ways to get the value but unable to do so, could anyone suggest how to get the values
I am able to get the value if I give the exact role but not all the roles and the value,
EXTRACTVALUE(s1.attributes, '/Attributes/Map/entry[@key="Role_111"]/value/List/String') as role
EXTRACTVALUE(s1.attributes, '/Attributes/Map/entry/descendant::*') as role
This solution is taken from this: http://sql-debug.blogspot.com/2012/05/extractvalue-only-constant-xpath.html
If you try to build up the xpath expression dynamically, MySQL throws an error:
To work around this you can wrap ExtractValue() in a UDF:
This query is very inefficient but it works:
Output:
The first derived table (
r) is used for the indices for the<entry>elements, and the second derived table (v) for the<String>elements.Here's a db<>fiddle