2015-02-05 75 views
0

我有一个.xsd文件,当然我可以从中创建一个.xml文件。所以基本上我有一个空白的.xml文件(没有数据/文本)PHP:读取现有的xml文件并写入新内容

使用PHP我想读取空白的.xml文件,交叉节点并根据标签填充数据库中的数据。

似乎有很多选择:XMLReader,XMLWriter,DOMDocument,SimpleXML 我不知道从哪里开始。最简单/最简单的方式是什么?

更多信息: Here you kann find the .xsd-file... 以下.xml文件我创建:

<?xml version="1.0" encoding="utf-8"?><Patienten> 
<InfoXML> 
    <DatumXML></DatumXML> 
    <NameTudokusys></NameTudokusys> 
    <VersionTudokusys></VersionTudokusys> 
</InfoXML> 
<Patient> 
    <Stammdaten> 
     <PatientID></PatientID> 
     <GeburtsJahr></GeburtsJahr> 
     <GeburtsMonat></GeburtsMonat> 
     <GeburtsTag></GeburtsTag> 
     <Geschlecht></Geschlecht> 
     <EinwilligungTumordoku></EinwilligungTumordoku> 
     <EinwilligungExterneStelle></EinwilligungExterneStelle> 
    </Stammdaten> 
    <Fall> 
     <Anamnese> 
      <RelevanteKrebsvorerkrankungen></RelevanteKrebsvorerkrankungen> 
      <JahrRelevanteKrebsvorerkrankungen></JahrRelevanteKrebsvorerkrankungen> 
      <NichtRelevanteKrebsvorerkrankungen></NichtRelevanteKrebsvorerkrankungen> 
      <JahrNichtRelevanteKrebsvorerkrankungen></JahrNichtRelevanteKrebsvorerkrankungen> 
      <DKGPatientenfragebogen></DKGPatientenfragebogen> 
      <PositiveFamilienanamnese></PositiveFamilienanamnese> 
     </Anamnese> 
     <Grundgesamtheiten></Grundgesamtheiten> 
     <Fallinfos> 
      <Zentrumsfall></Zentrumsfall> 
      <Organ></Organ> 
      <RegNr></RegNr> 
      <HauptNebenStandort></HauptNebenStandort> 
      <FallNummer></FallNummer> 
      <EingabeFalldaten></EingabeFalldaten> 
     </Fallinfos> 
     <Diagnose> 
      <DatumErstdiagnosePrimaertumor></DatumErstdiagnosePrimaertumor> 
      <DatumHistologischeSicherung></DatumHistologischeSicherung> 
      <ICDOHistologieDiagnose></ICDOHistologieDiagnose> 
      <Tumorauspraegung></Tumorauspraegung> 
      <ICDOLokalisation></ICDOLokalisation> 
      <KolonRektum></KolonRektum> 
      <TumorlokalisationRektum></TumorlokalisationRektum> 
      <praeT></praeT> 
      <praeN></praeN> 
      <praeM></praeM> 
      <UICCStadium></UICCStadium> 
      <SynchroneBehandlungKolorektalerPrimaertumoren></SynchroneBehandlungKolorektalerPrimaertumoren> 
      <MRTBecken></MRTBecken> 
      <CTBecken></CTBecken> 
      <AbstandFaszie></AbstandFaszie> 
     </Diagnose> 
     <PraetherapeutischeTumorkonferenz> 
      <VorstellungPraetherapeutischeTumorkonferenz></VorstellungPraetherapeutischeTumorkonferenz> 
      <EmpfehlungPraetherapeutischeTumorkonferenz></EmpfehlungPraetherapeutischeTumorkonferenz> 
     </PraetherapeutischeTumorkonferenz> 
     <EndoskopischePrimaertherapie> 
      <DatumTherapeutischeKoloskopie></DatumTherapeutischeKoloskopie> 
      <OPSCodeEndoskopischePrimaertherapie></OPSCodeEndoskopischePrimaertherapie> 
     </EndoskopischePrimaertherapie> 
     <ChirurgischePrimaertherapie> 
      <ASAKlassifikation></ASAKlassifikation> 
      <DatumOperativeTumorentfernung></DatumOperativeTumorentfernung> 
      <OPSCodesChirurgischePrimaertherapie></OPSCodesChirurgischePrimaertherapie> 
      <NotfallOderElektiveingriff></NotfallOderElektiveingriff> 
      <Erstoperateur></Erstoperateur> 
      <Zweitoperateur></Zweitoperateur> 
      <AnastomoseDurchgefuehrt></AnastomoseDurchgefuehrt> 
      <TMEDurchgefuehrt></TMEDurchgefuehrt> 
      <PostoperativeWundinfektion></PostoperativeWundinfektion> 
      <DatumPostoperativeWundinfektion></DatumPostoperativeWundinfektion> 
      <AufgetretenAnastomoseninsuffizienz></AufgetretenAnastomoseninsuffizienz> 
      <AnastomoseninsuffizienzInterventionspflichtig></AnastomoseninsuffizienzInterventionspflichtig> 
      <DatumInterventionspflichtigeAnastomoseninsuffizienz></DatumInterventionspflichtigeAnastomoseninsuffizienz> 
      <Revisionseingriff></Revisionseingriff> 
      <DatumRevisionseingriff></DatumRevisionseingriff> 
      <OPmitStoma></OPmitStoma> 
      <Stomaangezeichnet></Stomaangezeichnet> 
     </ChirurgischePrimaertherapie> 
     <PostoperativeHistologieStaging> 
      <pT></pT> 
      <pN></pN> 
      <postM></postM> 
      <Grading></Grading> 
      <ICDOHistologiePostoperative></ICDOHistologiePostoperative> 
      <PSRLokalNachAllenOPs></PSRLokalNachAllenOPs> 
      <PSRGesamtNachPrimaertherapie></PSRGesamtNachPrimaertherapie> 
      <GueteDerMesorektumresektion></GueteDerMesorektumresektion> 
      <AnzahlDerUntersuchtenLymphknoten></AnzahlDerUntersuchtenLymphknoten> 
      <AbstandAboralerTumorrand></AbstandAboralerTumorrand> 
      <AbstandZirkumferentiellerTumorrand></AbstandZirkumferentiellerTumorrand> 
     </PostoperativeHistologieStaging> 
     <PostoperativeTumorkonferenz> 
      <VorstellungPostoperativeTumorkonferenz></VorstellungPostoperativeTumorkonferenz> 
      <EmpfehlungPostoperativeTumorkonferenz></EmpfehlungPostoperativeTumorkonferenz> 
     </PostoperativeTumorkonferenz> 
     <Lebermetastasen> 
      <LebermetastasenVorhanden></LebermetastasenVorhanden> 
      <LebermetastasenAusschliesslich></LebermetastasenAusschliesslich> 
      <PrimaereLebermetastasenresektion></PrimaereLebermetastasenresektion> 
      <BedingungenSenkundaereLebermetastasenresektion></BedingungenSenkundaereLebermetastasenresektion> 
      <SekundaereLebermetastasenresektion></SekundaereLebermetastasenresektion> 
     </Lebermetastasen> 
     <PraeoperativeStrahlentherapie> 
      <EmpfehlungPraeoperativeStrahlentherapie></EmpfehlungPraeoperativeStrahlentherapie> 
      <DatumEmpfehlungPraeoperativeStrahlentherapie></DatumEmpfehlungPraeoperativeStrahlentherapie> 
      <TherapiezeitpunktPraeoperativeStrahlentherapie></TherapiezeitpunktPraeoperativeStrahlentherapie> 
      <TherapieintentionPraeoperativeStrahlentherapie></TherapieintentionPraeoperativeStrahlentherapie> 
      <GruendeFuerNichtdurchfuehrungPraeoperativeStrahlentherapie></GruendeFuerNichtdurchfuehrungPraeoperativeStrahlentherapie> 
      <DatumBeginnPraeoperativeStrahlentherapie></DatumBeginnPraeoperativeStrahlentherapie> 
      <DatumEndePraeoperativeStrahlentherapie></DatumEndePraeoperativeStrahlentherapie> 
      <GrundDerBeendigungDerPraeoperativeStrahlentherapie></GrundDerBeendigungDerPraeoperativeStrahlentherapie> 
     </PraeoperativeStrahlentherapie> 
     <PostoperativeStrahlentherapie> 
      <EmpfehlungPostoperativeStrahlentherapie></EmpfehlungPostoperativeStrahlentherapie> 
      <DatumEmpfehlungPostoperativeStrahlentherapie></DatumEmpfehlungPostoperativeStrahlentherapie> 
      <TherapiezeitpunktPostoperativeStrahlentherapie></TherapiezeitpunktPostoperativeStrahlentherapie> 
      <TherapieintentionPostoperativeStrahlentherapie></TherapieintentionPostoperativeStrahlentherapie> 
      <GruendeFuerNichtdurchfuehrungPostoperativeStrahlentherapie></GruendeFuerNichtdurchfuehrungPostoperativeStrahlentherapie> 
      <DatumBeginnPostoperativeStrahlentherapie></DatumBeginnPostoperativeStrahlentherapie> 
      <DatumEndePostoperativeStrahlentherapie></DatumEndePostoperativeStrahlentherapie> 
      <GrundDerBeendigungDerPostoperativeStrahlentherapie></GrundDerBeendigungDerPostoperativeStrahlentherapie> 
     </PostoperativeStrahlentherapie> 
     <PraeoperativeChemotherapie> 
      <EmpfehlungPraeoperativeChemotherapie></EmpfehlungPraeoperativeChemotherapie> 
      <DatumEmpfehlungPraeoperativeChemotherapie></DatumEmpfehlungPraeoperativeChemotherapie> 
      <TherapiezeitpunktPraeoperativeChemotherapie></TherapiezeitpunktPraeoperativeChemotherapie> 
      <TherapieintentionPraeoperativeChemotherapie></TherapieintentionPraeoperativeChemotherapie> 
      <GruendeFuerNichtdurchfuehrungPraeoperativeChemotherapie></GruendeFuerNichtdurchfuehrungPraeoperativeChemotherapie> 
      <DatumBeginnPraeoperativeChemotherapie></DatumBeginnPraeoperativeChemotherapie> 
      <DatumEndePraeoperativeChemotherapie></DatumEndePraeoperativeChemotherapie> 
      <GrundDerBeendigungDerPraeoperativeChemotherapie></GrundDerBeendigungDerPraeoperativeChemotherapie> 
     </PraeoperativeChemotherapie> 
     <PostoperativeChemotherapie> 
      <EmpfehlungPostoperativeChemotherapie></EmpfehlungPostoperativeChemotherapie> 
      <DatumEmpfehlungPostoperativeChemotherapie></DatumEmpfehlungPostoperativeChemotherapie> 
      <TherapiezeitpunktPostoperativeChemotherapie></TherapiezeitpunktPostoperativeChemotherapie> 
      <TherapieintentionPostoperativeChemotherapie></TherapieintentionPostoperativeChemotherapie> 
      <GruendeFuerNichtdurchfuehrungPostoperativeChemotherapie></GruendeFuerNichtdurchfuehrungPostoperativeChemotherapie> 
      <DatumBeginnPostoperativeChemotherapie></DatumBeginnPostoperativeChemotherapie> 
      <DatumEndePostoperativeChemotherapie></DatumEndePostoperativeChemotherapie> 
      <GrundDerBeendigungDerPostoperativeChemotherapie></GrundDerBeendigungDerPostoperativeChemotherapie> 
     </PostoperativeChemotherapie> 
     <BestSupportiveCare></BestSupportiveCare> 
     <Prozess> 
      <DatumStudie></DatumStudie> 
      <Studientyp></Studientyp> 
      <PsychoonkologischeBetreuung></PsychoonkologischeBetreuung> 
      <BeratungSozialdienst></BeratungSozialdienst> 
      <GenetischeBeratungEmpfohlen></GenetischeBeratungEmpfohlen> 
      <GenetischeBeratungErhalten></GenetischeBeratungErhalten> 
      <ImmunhistochemischeUntersuchungAufMSI></ImmunhistochemischeUntersuchungAufMSI> 
     </Prozess> 
     <FollowUp> 
      <DatumFollowUp></DatumFollowUp> 
      <LokoregionaeresRezidiv></LokoregionaeresRezidiv> 
      <LymphknotenRezidiv></LymphknotenRezidiv> 
      <Fernmetastasen></Fernmetastasen> 
      <Zweittumor></Zweittumor> 
      <Verstorben></Verstorben> 
      <QuelleFollowUp></QuelleFollowUp> 
     </FollowUp> 
    </Fall> 
</Patient> 

首先,我必须导航到某些节点(例如, “DatumXML”)和输入值。 其次,我必须遍历某些节点的所有子节点(例如Stammdaten)并输入值。

+0

我通过编辑我的问题提供了更多信息。我如何摆脱“持有状态”? – Phantom 2015-02-09 12:55:23

回答

0

我认为SimpleXMLIterator将是你最好的选择。你不太解释你的XML的结构,但你应该能够做到像:

$iterator = new SimpleXMLIterator($xml); 
for ($iterator->rewind(); $iterator->valid(); $iterator->next()) { 
    $node = $iterator->key(); 

    // Get data from database based on node name 
    $iterator->{$node} = $data; 
} 

$finished_xml = $iterator->asXML(); 

如果你是结构比较复杂,你应该能够这个适应你的需要。请记住,SimpleXMLIterator是一个SimpleXMLElement,您可以使用相同的方法和技巧。

+0

非常感谢您的支持者。我添加了一些详细信息。 – Phantom 2015-02-07 21:45:18