I have a tables countries which is containing the required xml. Assume this table is in the postgres db. below is the xml from the table countries
<config>
<classification Master="Y" Database="Y">
<lookup >
<countries>
<cities>
<city name="Bangalore">Bangalore</city>
<city name="Delhi">Delhi</city>
<city name="Mumbai">Mumbai</city>
</cities>
</countries>
</lookup>
</classification>
</config>
I am writing the query to get the result from the table:
select unnest(xpath('/config/classification/lookup', data)), xpath('/config/classification/attribute::*', data) from Countries;
| <lookup > |
| <countries> |
| <cities> |
| <city name="bangalore">Bangalore</city> |
| <city name="delhi">Delhi</city> |
| <city name="mumbai">Mumbai</city> |
| </cities> |
| </countries> |
|</lookup> | Y, Y
but i am expecting something to achieve the below result
|<lookup > |
| <countries> |
| <cities> |
| <city name="bangalore">Bangalore</city> |
| <city name="delhi">Delhi</city> |
| <city name="mumbai">Mumbai</city> |
| </cities> |
| </countries> |
| </lookup> | Master="Y" Database="Y"
I am not sure if it can be achieved, if yes please expecting the query. One condition it can be any number of attributes and i don not want to hard code any attribute name. I want all the attributes name and also the value.
name()(which would include namespace-prefix) orlocal-name()functions.