0

I have a xml file which has array attributes and normal attribute. I need to store these array attributes and normal values into a postgresql table.

-<sample-test>
     <BookerNo>50105</BookerNo>
     <Type>
         <V Idx="1">A</V>
         <V Idx="2">B</V>
     </Type>
     <Value>
         <V Idx="1">50108</V>
         <V Idx="2">50158</V>
     </Value>
</sample-test>
-<sample-test>
     <BookerNo>50106</BookerNo>
     <Type>
         <V Idx="1">A</V>
         <V Idx="2">B</V>
         <V Idx="3">C</V>
     </Type>
     <Value>
         <V Idx="1">60108</V>
         <V Idx="2">60135</V>
         <V Idx="3">60158</V>
     </Value>
</sample-test>

Table name sample

col1    col2    col3   col4
1      50105     A     50108
2      50105     B     50158
3      50106     A     60108
4      50106     B     60135
5      50106     C     60158
Anoop
  • 33
  • 5
  • See [Extract data from a Postgres XML column using XPath](https://stackoverflow.com/q/55847671/1995738) – klin Apr 25 '19 at 14:59
  • Thanks Klin for the response. But it is not working in my situation since my file is xmlns file eg – Anoop Apr 26 '19 at 12:31
  • You have to have the data in the database to use Postgres function `xpath()`. You can import the file to a temp table using [`COPY`](https://www.postgresql.org/docs/current/sql-copy.html) command. Alternatively, you can parse the xml file with e.g. python script and one of its [xml parsers.](https://stackoverflow.com/q/1912434/1995738) – klin Apr 26 '19 at 13:18

0 Answers0