I have sample XML files, where i need to ready Node name & create table name similar to Node name skipping container nodes. Then read these XML Nodes and create Dynamic table with dynamic columns in Postgres sql Script file. This file will be executed by existing framework written to create sample database for microservices.
Sample XML –
<Base>
<Data>
<UserContainer>
<user>
<ID>C1234</ID>
<Name>name1</Name>
</user>
</UserContainer>
<AddressContainer>
<Address>
<ID>A123</ID>
<Address1>TestAddress</Address1>
</Address>
</AddressContainer>
</Data>
<Data>
<UserContainer>
<user>
<ID>C1234</ID>
<Name>name1</Name>
</user>
</UserContainer>
<AddressContainer>
<Address>
<ID>A123</ID>
<Address1>TestAddress</Address1>
</Address>
</AddressContainer>
</Data>
</Base>
so output of this xml reading should be as follows –
Dynamic User table with columns ID, Name
Dynamic Address table with columns ID, Address1
After creating these tables, same values should be inserted into User and Address tables from xml nodes.
2
Answers
I tried above solution -
Node name and child nodes are not getting populated. Not sure if something i'm missing.
you can use PL/pgSQL along with the XML functions to dynamically create tables based on XML structure and insert data into these tables.
can use this function by passing your xml data as an argument.