2016-10-18 5 views
0

Wie würde ich die folgende XML in eine SQL-Tabelle importieren, die untergeordneten Elemente, die mit IP tpl angeben, werden für die Menge pro XML-Datensatz variieren. Ich denke, das Hauptproblem ist die Handhabung der variablen Anzahl Kind Elemente, wenn das der richtige Begriff ist?Importieren von XML in Sql

Dank

<?xml version="1.0" encoding="utf-8"?> 
<PportTimetable xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" timetableID="20161018020822" xmlns="http://www.thalesgroup.com/rtti/XmlTimetable/v8"> 
<Journey rid="201610188012733" uid="P12733" trainId="2J27" ssd="2016-10-18" toc="AW"> 
<OR tpl="MCHYNLT" act="TB" ptd="21:43" wtd="21:43" /> 
<IP tpl="DOVYJN" act="T " pta="21:49" ptd="21:49" wta="21:48:30" wtd="21:49:30" /> 
<IP tpl="PENHELG" act="R " plat="1" pta="21:58" ptd="21:58" wta="21:58:30" wtd="21:59" /> 
<IP tpl="ABDVY" act="T " plat="1" pta="22:01" ptd="22:02" wta="22:01:30" wtd="22:02" /> 
<IP tpl="TYWYN" act="T X " plat="2" pta="22:11" ptd="22:15" wta="22:11" wtd="22:15" /> 
<IP tpl="TONFNAU" act="R " plat="1" pta="22:18" ptd="22:18" wta="22:19" wtd="22:19:30" /> 
<IP tpl="LYNGRIL" act="R " plat="1" pta="22:25" ptd="22:25" wta="22:25:30" wtd="22:26" /> 
<IP tpl="FRBN" act="T " plat="1" pta="22:32" ptd="22:33" wta="22:33" wtd="22:33:30" /> 
<IP tpl="MFAM" act="R " plat="1" pta="22:35" ptd="22:35" wta="22:35:30" wtd="22:36" /> 
<IP tpl="BRMOUTH" act="T X " pta="22:44" ptd="22:46" wta="22:45" wtd="22:46:30" /> 
<IP tpl="LNAB" act="R " plat="1" pta="22:49" ptd="22:50" wta="22:50" wtd="22:51" /> 
<IP tpl="TALB" act="R " plat="1" pta="22:53" ptd="22:53" wta="22:55" wtd="22:55:30" /> 
<IP tpl="DYFRYNA" act="R " plat="1" pta="22:56" ptd="22:56" wta="22:58" wtd="22:58:30" /> 
<IP tpl="LBDR" act="R " plat="1" pta="23:00" ptd="23:00" wta="23:02" wtd="23:02:30" /> 
<IP tpl="PSRN" act="R " plat="1" pta="23:03" ptd="23:03" wta="23:04:30" wtd="23:05" /> 
<IP tpl="LNDW" act="R " plat="1" pta="23:05" ptd="23:05" wta="23:06:30" wtd="23:07" /> 
<IP tpl="HRLC" act="T " plat="2" pta="23:10" ptd="23:13" wta="23:12" wtd="23:13" /> 
<IP tpl="TYGWYN" act="R " plat="1" pta="23:16" ptd="23:16" wta="23:17" wtd="23:17:30" /> 
<IP tpl="TLSRNAU" act="R " plat="1" pta="23:19" ptd="23:19" wta="23:19:30" wtd="23:20" /> 
<IP tpl="LNDC" act="R " plat="1" pta="23:22" ptd="23:22" wta="23:22:30" wtd="23:23" /> 
<IP tpl="PRHN" act="T " plat="1" pta="23:25" ptd="23:26" wta="23:25:30" wtd="23:26" /> 
<IP tpl="MINFORD" act="T " plat="1" pta="23:29" ptd="23:29" wta="23:29" wtd="23:29:30" /> 
<IP tpl="PRTHMDG" act="T " pta="23:37" ptd="23:37" wta="23:36:30" wtd="23:37:30" /> 
<IP tpl="CRICCTH" act="T " plat="1" pta="23:45" ptd="23:45" wta="23:44:30" wtd="23:45" /> 
<IP tpl="PENYCHN" act="R " plat="1" pta="23:50" ptd="23:50" wta="23:50:30" wtd="23:51:30" /> 
<IP tpl="ABRE" act="R " plat="1" pta="23:53" ptd="23:53" wta="23:54:30" wtd="23:55" /> 
<DT tpl="PWLHELI" act="TF" plat="1" pta="23:59" wta="23:59" /> 
</Journey> 
<Journey rid="201610186765436" uid="C65436" trainId="2S07" ssd="2016-10-18" toc="EM"> 
<OR tpl="NTNG" act="TB" plat="4" ptd="07:35" wtd="07:35" /> 
<PP tpl="NTHRFLJ" wtp="07:40" /> 
<IP tpl="BINGHAM" act="T " plat="2" pta="07:49" ptd="07:49" wta="07:48:30" wtd="07:49" /> 
<IP tpl="ASLCKTN" act="T " plat="1" pta="07:53" ptd="07:53" wta="07:52:30" wtd="07:53" /> 
<PP tpl="BOTESWJ" wtp="07:57" /> 
<IP tpl="BOTESFD" act="T " plat="2" pta="07:59" ptd="07:59" wta="07:59" wtd="07:59:30" /> 
<PP tpl="ALNGJN" wtp="08:06:30" /> 
<PP tpl="GTHMNBJ" wtp="08:10" /> 
<IP tpl="GTHM" act="T RM" plat="4" pta="08:12" ptd="08:16" wta="08:12" wtd="08:16" /> 
<PP tpl="GTHMNBJ" wtp="08:18" /> 
<PP tpl="ALNGEJN" wtp="08:22" /> 
<PP tpl="ALNGNJN" wtp="08:22:30" /> 
<IP tpl="ANCASTR" act="T " plat="2" pta="08:34" ptd="08:34" wta="08:34" wtd="08:34:30" /> 
<IP tpl="RAUCEBY" act="T " plat="2" pta="08:40" ptd="08:40" wta="08:40" wtd="08:42" /> 
<IP tpl="SLEFD" act="T " plat="1" pta="08:44" ptd="08:45" wta="08:46" wtd="08:47:30" /> 
<IP tpl="HCKNGTN" act="T " plat="2" pta="08:52" ptd="08:52" wta="08:54" wtd="08:54:30" /> 
<PP tpl="HBRTBDG" wtp="09:03:30" /> 
<IP tpl="BOSTON" act="T " plat="2" pta="09:11" ptd="09:12" wta="09:11" wtd="09:12" /> 
<PP tpl="SIBSEY" wtp="09:19:30" /> 
<PP tpl="BELWTRJ" wtp="09:26" /> 
<IP tpl="WAINFLT" act="T " plat="2" pta="09:36" ptd="09:36" wta="09:35:30" wtd="09:36:30" /> 
<DT tpl="SKEGNES" act="TF" pta="09:49" wta="09:48" /> 
</Journey> 

Haben Sie gründlich nach einer Antwort gesucht, bevor Sie Ihre Frage stellen? Teilen Sie Ihre Forschung hilft allen. Sagen Sie uns, was Sie gefunden haben (auf dieser Seite oder anderswo) und warum es nicht Ihren Bedürfnissen entspricht. Dies zeigt, dass Sie sich die Zeit genommen haben, sich selbst zu helfen, es erspart uns, die offensichtlichen Antworten zu wiederholen, und vor allem hilft es Ihnen, eine spezifischere und relevantere Antwort zu erhalten!

+0

Bitte geben Sie Ihre Tabellenstruktur. Welche Tag-Daten sollten in welche Spalte gelangen? Machen Sie das so klar –

+0

Welches RDBMS? Das Tag 'sql' ist nicht genug ... – Shnugo

Antwort

0


Hallo,
Sie können SQL Loader verwenden, um XML-Daten in Tabellen in SQL zu importieren. Es gibt eine Option als SQL-Loader, bei dem es sich um einen Batch handelt. Beim Klicken werden die Daten in Tabellen importiert. Dazu müssen Sie eine Protokolldatei, eine Kontrolldatei und eine Batch-Datei haben und einen Code in der Kontrolldatei haben, wie er geladen werden soll. Wenn Sie die Beispiel-XML-Daten und die Tabellenstruktur bereitstellen könnten, ist es hilfreich, Ihnen eine genaue Lösung zu geben.
Schauen Sie sich dies als Referenz an - Can Oracle SQL*Loader process XML?

+0

Idealerweise wäre dies für eine azure SQL-Datenbank – user3129787