0

I have a .xsd-file and of course I can create a .xml-file from it. So basically I have a blank .xml-file (with no data/text)

With PHP I want to read the blank .xml-file, interate the nodes and fill them depending on the tag with data from the database.

There seem to be many options: XMLReader, XMLWriter, DOMDocument, SimpleXML I don't know where to start. What would be the easies/leanest way?

More Information: Here you kann find the .xsd-file... The following .xml-file I created:

<?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>

First, I have to navigate to certain nodes (for example "DatumXML") and enter a value. Second, I have to iterate all subnodes of certain nodes (for example Stammdaten) and enter values.

1
  • I provided more information by editing my question. How do I get away the "hold status"? Commented Feb 9, 2015 at 12:55

1 Answer 1

0

I think the SimpleXMLIterator is going to be your best bet. You didn't quite explain the structure of your XML, but you should be able to do something like:

$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();

If you're structure is more complex, you should be able to adapt this to what you need. Just remember that a SimpleXMLIterator is a SimpleXMLElement and you can use the same methods and techniques.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for your anser. I added some detailed information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.