A few days ago I managed it to export 3 different PgSQL tables into one XML file. Now, I'd like to import the Same file. I've searched for about 2 hours but only found solutions for Importing a XML into one Table. Here ist the structure of the XML
<?xml version="1.0" encoding="UTF-8"?>
<Table1 Col1="xxx" Col2="xxx">
<Table2 Col1="xxx">
<Table3 Col1="xxx" Col2="xxx" Coln="xxx"/>
</Table2>
<Table2 Col1="xxx"/>
<Table2 Col1="xxx">
<Table3 Col1="xxx" Col2="xxx" Coln="xxx"/>
</Table2>
</Table1>
Table 1 contains Table 3 and table 2 contains Table 3.
The tables are XMLWriterElements, the columns XMLWriterAttributes.
UPDATE: I solved the problem and want to show you my results, if someone ha the same or similar problem:
$reader = new XMLReader();
if ($reader->open("tk.xml")) {
while($reader->read()) {
if ($reader->nodeType == XMLReader::ELEMENT &&reader->name == 'Table 1') {
$knr = $reader->getAttribute('Col1');
$kname = $reader->getAttribute('Col2');
$SQL = "";
$SQL .= "SELECT
(table1).col1 AS col1, (table1).col2 AS col1
FROM
table1
";
$SQL .= "INSERT INTO table1 (";
$SQL .= "col1, col1";
$SQL .= ") VALUES (";
$SQL .= "'".$col1."', '".$col1."'";
$SQL .= ");".PHP_EOL;
echo $SQL;
}
if ($reader->nodeType == XMLReader::ELEMENT
&&reader->name == 'Table 2') { ......}
if ($reader->nodeType == XMLReader::ELEMENT
&&reader->name == 'Table 3') { ......}
}
$reader->close();
}
I hope, thos code will help someone.
, not ANSI SQL style quoting with"`. You are also, against my explicit advice, concatenating values in your SQL and leaving you wide open for SQL injection if you execute that SQL.