7

this is an xml file i had received and i want to generate the same output with delphi. I used the delphi xml wizard to generate a big unit by my schema.

So this is the output i want to have (original file)

<?xml version="1.0" encoding="iso-8859-1"?><reh:Reha xmlns:reh="http://www.vdek.com/xml-schema/REH/1.8">
  <reh:logische_Version>1.6.0</reh:logische_Version> 
 <reh:KV>
 <reh:Kopfdaten>
  <kod:Erstellungsdatum_Uhrzeit xmlns:kod="http://www.vdek.com/xml-schema/KOD/1.2">2014-09-23T15:33:23</kod:Erstellungsdatum_Uhrzeit> 
  <kod:Version xmlns:kod="http://www.vdek.com/xml-schema/KOD/1.2">1.2.0</kod:Version> 
  <kod:Dateinummer xmlns:kod="http://www.vdek.com/xml-schema/KOD/1.2">000010</kod:Dateinummer> 
 <kod:Identifikationsdaten xmlns:kod="http://www.vdek.com/xml-schema/KOD/1.2">
  <kod:IK_Absender>108018007</kod:IK_Absender> 
  <kod:IK_Empfaenger>510800000</kod:IK_Empfaenger> 
  <kod:IK-Kostentraeger>108018007</kod:IK-Kostentraeger> 
  <kod:IK_Einrichtung>510800000</kod:IK_Einrichtung> 
  </kod:Identifikationsdaten>
 <kod:Fall_ID_KV xmlns:kod="http://www.vdek.com/xml-schema/KOD/1.2">
  <kod:Krankenversichertennummer>I123456789</kod:Krankenversichertennummer> 
  <kod:Versichertenstatus>50001</kod:Versichertenstatus> 
  <kod:Kartengueltigkeit>1712</kod:Kartengueltigkeit> 
  <kod:Fallnummer>01800000099988877</kod:Fallnummer> 
  </kod:Fall_ID_KV>
    <reh:Dateinummer></reh:Dateinummer>
    </reh:Kopfdaten>
 <reh:Bewilligung>
 <bew:Admindaten xmlns:bew="http://www.vdek.com/xml-schema/BEW/1.5">
  <bew:Verarbeitungskennzeichen>10</bew:Verarbeitungskennzeichen> 
  <bew:Version>1.5.0</bew:Version> 
  <bew:LfdNr>01</bew:LfdNr> 
  </bew:Admindaten>
 <bew:Fachliche_Daten xmlns:bew="http://www.vdek.com/xml-schema/BEW/1.5">
 <bew:Rehabilitand>
  <bew:Anrede>1</bew:Anrede> 
 <bew:Name>
  <bty:Nachname xmlns:bty="http://www.vdek.com/xml-schema/BTY/1.2">Mustermann</bty:Nachname> 
  <bty:Vorname xmlns:bty="http://www.vdek.com/xml-schema/BTY/1.2">Max</bty:Vorname> 
  </bew:Name>
  <bew:Geschlecht>1</bew:Geschlecht> 
  <bew:Geburtsdatum>1950-08-21</bew:Geburtsdatum> 
 <bew:Adresse>
  <bty:Strasse xmlns:bty="http://www.vdek.com/xml-schema/BTY/1.2">Saonestr.</bty:Strasse> 
  <bty:Hausnummer xmlns:bty="http://www.vdek.com/xml-schema/BTY/1.2">3</bty:Hausnummer> 
  <bty:Wohnort xmlns:bty="http://www.vdek.com/xml-schema/BTY/1.2">Frankfurt</bty:Wohnort> 
  <bty:PLZ xmlns:bty="http://www.vdek.com/xml-schema/BTY/1.2">60528</bty:PLZ> 
  <bty:Laenderkennzeichen xmlns:bty="http://www.vdek.com/xml-schema/BTY/1.2">D</bty:Laenderkennzeichen> 
  </bew:Adresse>
 <bew:Kommunikation>
  <bty:Telefon xmlns:bty="http://www.vdek.com/xml-schema/BTY/1.2">069/12345</bty:Telefon> 
  </bew:Kommunikation>
  </bew:Rehabilitand>
 <bew:Kosteninformationen>
 <bew:Zuzahlung>
  <bew:Zuzahlungseinzug>2</bew:Zuzahlungseinzug> 
  <bew:AnzahlTage>028</bew:AnzahlTage> 
  <bew:Zuzahlungsbetrag>01000</bew:Zuzahlungsbetrag> 
  </bew:Zuzahlung>
  </bew:Kosteninformationen>
 <bew:Rehainformationen>
  <bew:Rehaart>93</bew:Rehaart> 
  </bew:Rehainformationen>
 <bew:Aufnahmedaten>
  <bew:IK_Krankenhaus>260612124</bew:IK_Krankenhaus> 
  <bew:Behandlungsart>1</bew:Behandlungsart> 
 <bew:Bewilligungsdiagnosen>
  <bew:Version_ICD>2014</bew:Version_ICD> 
 <bew:Diagnose>
  <bty:Diagnosenschluessel xmlns:bty="http://www.vdek.com/xml-schema/BTY/1.2">M151</bty:Diagnosenschluessel> 
  </bew:Diagnose>
  </bew:Bewilligungsdiagnosen>
 <bew:Aufnahmedaten>
  <bew:Erfolgt>N</bew:Erfolgt> 
  <bew:Geplant>2014-10-05</bew:Geplant> 
  </bew:Aufnahmedaten>
  <bew:Indikationsgruppe>SA</bew:Indikationsgruppe> 
  </bew:Aufnahmedaten>
 <bew:Bewilligungsinformationen>
  <bew:Bewilligungsdatum>2014-09-23</bew:Bewilligungsdatum> 
  <bew:Kostenzusage_gueltig_bis>2014-10-31</bew:Kostenzusage_gueltig_bis> 
  </bew:Bewilligungsinformationen>
 <bew:Stationaerdaten>
  <bew:Behandlungsabschnitte>01</bew:Behandlungsabschnitte> 
  <bew:bewilligte_Tage>020</bew:bewilligte_Tage> 
  </bew:Stationaerdaten>
  </bew:Fachliche_Daten>
    <reh:Fachliche_Daten>
        <reh:Rehabilitand/>
      </reh:Fachliche_Daten>
    </reh:Bewilligung>
  </reh:KV>
  <reh:Papieranlage>N</reh:Papieranlage> 
  </reh:Reha>

My delphi code

var
 XML: IXMLReha;
begin
  XML := NewReha;
  XML.OwnerDocument.Options := [doNodeAutoCreate, doNodeAutoIndent];
  XML.Logische_Version := '1.6.0';

  //Präfixe wie :bs, :reh fehlen noch

  {Kopfdaten}       //xmlns:kod
  Xml.KV.Kopfdaten.DeclareNamespace('kod', 'http://www.vdek.com/xml-schema/KOD/1.2');
  Xml.KV.Kopfdaten.Attributes['test'] := 'test2';

  XML.KV.Kopfdaten.Erstellungsdatum_Uhrzeit             := '2014-09-23T15:33:23';
  XML.KV.Kopfdaten.Version                              := '1.2.0';
  XML.KV.Kopfdaten.Dateinummer                          := '000010';

  XML.KV.Kopfdaten.Identifikationsdaten.IK_Absender     := '108018007';
  XML.KV.Kopfdaten.Identifikationsdaten.IK_Empfaenger   := '510800000';
  XML.KV.Kopfdaten.Identifikationsdaten.IKKostentraeger := '108018007';
  XML.KV.Kopfdaten.Identifikationsdaten.IK_Einrichtung  := '510800000';

  XML.KV.Kopfdaten.Fall_ID_KV.Krankenversichertennummer := 'I123456789';
  XML.KV.Kopfdaten.Fall_ID_KV.Versichertenstatus        := '50001';
  XML.KV.Kopfdaten.Fall_ID_KV.Kartengueltigkeit         := '1712';
  XML.KV.Kopfdaten.Fall_ID_KV.Fallnummer                := '01800000099988877';
  XML.KV.Kopfdaten.Dateinummer                          := '';


  {Bewilligung}
  XML.KV.Bewilligung.Admindaten.Verarbeitungskennzeichen := '10';
  XML.KV.Bewilligung.Admindaten.Version                  := '1.5.0';
  XML.KV.Bewilligung.Admindaten.LfdNr                    := '01';

  XML.KV.Bewilligung.Fachliche_Daten.Rehabilitand.Anrede         := '1';
  XML.KV.Bewilligung.Fachliche_Daten.Rehabilitand.Name.Nachname  := 'Mustermann';
  XML.KV.Bewilligung.Fachliche_Daten.Rehabilitand.Name.Vorname   := 'Max';

  XML.KV.Bewilligung.Fachliche_Daten.Rehabilitand.Geschlecht := '1';
  XML.KV.Bewilligung.Fachliche_Daten.Rehabilitand.Geburtsdatum := '1950-08-21';

  XML.KV.Bewilligung.Fachliche_Daten.Rehabilitand.Adresse.Strasse := 'Saonestr';
  XML.KV.Bewilligung.Fachliche_Daten.Rehabilitand.Adresse.Hausnummer := '3';
  XML.KV.Bewilligung.Fachliche_Daten.Rehabilitand.Adresse.Wohnort := 'Frankfurt';
  XML.KV.Bewilligung.Fachliche_Daten.Rehabilitand.Adresse.PLZ := '60528';
  XML.KV.Bewilligung.Fachliche_Daten.Rehabilitand.Adresse.Laenderkennzeichen := 'D';

  XML.KV.Bewilligung.Fachliche_Daten.Rehabilitand.Kommunikation.Telefon := '069/12345';

  { ...}

  //Dokument speichern
  XML.OwnerDocument.SaveToFile('\\Server\Gen.xml');
end;

My output generated with my delphi code

<?xml version="1.0"?>
<Reha xmlns="http://www.vdek.com/xml-schema/REH/1.8" xsi:schemaLocation="http://www.foo.com/Myxsd.xsd">
  <logische_Version>1.6.0</logische_Version>
  <KV>
    <Kopfdaten xmlns:kod="http://www.vdek.com/xml-schema/KOD/1.2" test="test2">
      <Erstellungsdatum_Uhrzeit>2014-09-23T15:33:23</Erstellungsdatum_Uhrzeit>
      <Version>1.2.0</Version>
      <Dateinummer></Dateinummer>
      <Identifikationsdaten>
        <IK_Absender>108018007</IK_Absender>
        <IK_Empfaenger>510800000</IK_Empfaenger>
        <IK-Kostentraeger>108018007</IK-Kostentraeger>
        <IK_Einrichtung>510800000</IK_Einrichtung>
      </Identifikationsdaten>
      <Fall_ID_KV>
        <Krankenversichertennummer>I123456789</Krankenversichertennummer>
        <Versichertenstatus>50001</Versichertenstatus>
        <Kartengueltigkeit>1712</Kartengueltigkeit>
        <Fallnummer>01800000099988877</Fallnummer>
      </Fall_ID_KV>
    </Kopfdaten>
    <Bewilligung>
      <Admindaten>
        <Verarbeitungskennzeichen>10</Verarbeitungskennzeichen>
        <Version>1.5.0</Version>
        <LfdNr>01</LfdNr>
      </Admindaten>
      <Fachliche_Daten>
        <Rehabilitand>
          <Anrede>1</Anrede>
          <Name>
            <Nachname>Mustermann</Nachname>
            <Vorname>Max</Vorname>
          </Name>
          <Geschlecht>1</Geschlecht>
          <Geburtsdatum>1950-08-21</Geburtsdatum>
          <Adresse>
            <Strasse>Saonestr</Strasse>
            <Hausnummer>3</Hausnummer>
            <Wohnort>Frankfurt</Wohnort>
            <PLZ>60528</PLZ>
            <Laenderkennzeichen>D</Laenderkennzeichen>
          </Adresse>
          <Kommunikation>
            <Telefon>069/12345</Telefon>
          </Kommunikation>
        </Rehabilitand>
      </Fachliche_Daten>
    </Bewilligung>
  </KV>
</Reha>

So how can i set the prefixes/namespaces like reh:, :kod ... in ym xml file like in original xml file ?

As you see i dont use the ".addchild" command so i need a different answer.

Hidden
  • 3,598
  • 4
  • 34
  • 57
  • possible duplicate of [How to set the prefix of a document element in Delphi](http://stackoverflow.com/questions/3119314/how-to-set-the-prefix-of-a-document-element-in-delphi) – Sir Rufo Apr 08 '15 at 07:06
  • Its smilar yes, but as you can see i dont work with "AddChild" so the solution makes no sense for me. Thats why i asked – Hidden Apr 08 '15 at 07:13
  • How about using XSLT to perform this transformation? Can you apply XSLT stylesheets in Delphi? – Mathias Müller Apr 08 '15 at 08:31
  • Cant answer your question because i dont know what "XSLT" meant to be – Hidden Apr 08 '15 at 08:57
  • possible duplicate of [How do I add a namespace prefix to each node using TXMLDocument](http://stackoverflow.com/questions/3989012/how-do-i-add-a-namespace-prefix-to-each-node-using-txmldocument) – whosrdaddy Apr 08 '15 at 09:00
  • XSLT transforms XML documents into other XML documents. (I won't be notified if you do not ping me using "@".) – Mathias Müller Apr 08 '15 at 09:08
  • @MathiasMüller alright. Is there any docu/tutorial for it? It really sucks if you do some research for delphi and most of questions were older than 15 years or something or seem not smilar to my problem... – Hidden Apr 08 '15 at 09:37
  • I don't know Delphi unfortunately, how about http://www.drbob42.com/examines/examin50.htm or http://stackoverflow.com/questions/982687/how-do-i-display-xml-using-an-xslt-document-in-a-delphi-app or http://edn.embarcadero.com/article/27106? Once you get XSLT transformations to work, you can generate _any_ XML output. You'd just need a stylesheet that does the job, but you could ask for it here. (That is, if I understood correctly that you'd like to change an input XML document to another XML document.) – Mathias Müller Apr 08 '15 at 09:42
  • @whosrdaddy sure but thats not solving my problem because ALL NODES HAVE THE SAME PREFIX. Screenshot. http://i.imgur.com/zmL78yi.png So i need different prefixes for each node like in my first xml example :) watch it again – Hidden Apr 08 '15 at 14:13
  • No need to shout, I am aware that you have different prefixes, I'm just saying that it is not impossible. I will look into this tomorrow when I have access to Delphi :) – whosrdaddy Apr 08 '15 at 14:38
  • And FYI the dupe link also informs you how to solve this problem via XSL tranformation... – whosrdaddy Apr 08 '15 at 14:40
  • Could you please do an answer that would be great :-) If you want i also could start a bounty for higher motivation – Hidden Apr 08 '15 at 15:37
  • can you share the WSDL, is it available online somewhere? – whosrdaddy Apr 08 '15 at 17:52
  • *XSLT? Is there any docu/tutorials for it?" Never heard of Google? Bing? – Ken White Apr 08 '15 at 22:27
  • I have a xsd not a wsdl – Hidden Apr 09 '15 at 08:43
  • Hi, did you see my anwer? – whosrdaddy Apr 10 '15 at 08:01
  • yes. i posted a comment :) – Hidden Apr 15 '15 at 12:21
  • Have you tried to use `msxml.IXMLDOMDocument` `createNode` method? You can specify a namespace for the node name there. – kot-da-vinci Apr 17 '15 at 06:10
  • @kot-da-vinci Can you post an example using? – Hidden Apr 17 '15 at 08:47

4 Answers4

3

If you have a complex XSD schema, consisting of multiple files the XML databinding wizard fails to create the correct code (like you have noticed). In that case, it is easier to feed the wanted output to an online XML to XSD converter and use that as the input for the databinding wizard. I crafted a new XSD file (generated from the XML file you posted here), using the excellent XMLgrid converter

<?xml version="1.0" encoding="UTF-8"?>
   <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
         <!-- XML Schema Generated from XML Document on Thu Apr 09 2015 14:31:00 GMT+0200 (Romance Daylight Time) -->
         <!-- with XmlGrid.net Free Online Service http://xmlgrid.net -->
         <xs:element name="reh:Reha">
               <xs:complexType>
                     <xs:sequence>
                           <xs:element name="reh:logische_Version" type="xs:string"></xs:element>
                           <xs:element name="reh:KV">
                                 <xs:complexType>
                                       <xs:sequence>
                                             <xs:element name="reh:Kopfdaten">
                                                   <xs:complexType>
                                                         <xs:sequence>
                                                               <xs:element name="kod:Erstellungsdatum_Uhrzeit" type="xs:dateTime">
                                                                     <xs:complexType>
                                                                           <xs:attribute name="xmlns:kod" type="xs:string"></xs:attribute>
                                                                     </xs:complexType>
                                                               </xs:element>
                                                               <xs:element name="kod:Version" type="xs:string">
                                                                     <xs:complexType>
                                                                           <xs:attribute name="xmlns:kod" type="xs:string"></xs:attribute>
                                                                     </xs:complexType>
                                                               </xs:element>
                                                               <xs:element name="kod:Dateinummer" type="xs:string">
                                                                     <xs:complexType>
                                                                           <xs:attribute name="xmlns:kod" type="xs:string"></xs:attribute>
                                                                     </xs:complexType>
                                                               </xs:element>
                                                               <xs:element name="kod:Identifikationsdaten">
                                                                     <xs:complexType>
                                                                           <xs:sequence>
                                                                                 <xs:element name="kod:IK_Absender" type="xs:string"></xs:element>
                                                                                 <xs:element name="kod:IK_Empfaenger" type="xs:string"></xs:element>
                                                                                 <xs:element name="kod:IK-Kostentraeger" type="xs:string"></xs:element>
                                                                                 <xs:element name="kod:IK_Einrichtung" type="xs:string"></xs:element>
                                                                           </xs:sequence>
                                                                           <xs:attribute name="xmlns:kod" type="xs:string"></xs:attribute>
                                                                     </xs:complexType>
                                                               </xs:element>
                                                               <xs:element name="kod:Fall_ID_KV">
                                                                     <xs:complexType>
                                                                           <xs:sequence>
                                                                                 <xs:element name="kod:Krankenversichertennummer" type="xs:string"></xs:element>
                                                                                 <xs:element name="kod:Versichertenstatus" type="xs:string"></xs:element>
                                                                                 <xs:element name="kod:Kartengueltigkeit" type="xs:string"></xs:element>
                                                                                 <xs:element name="kod:Fallnummer" type="xs:string"></xs:element>
                                                                           </xs:sequence>
                                                                           <xs:attribute name="xmlns:kod" type="xs:string"></xs:attribute>
                                                                     </xs:complexType>
                                                               </xs:element>                                                               
                                                         </xs:sequence>
                                                   </xs:complexType>
                                             </xs:element>
                                             <xs:element name="reh:Bewilligung">
                                                   <xs:complexType>
                                                         <xs:sequence>
                                                               <xs:element name="bew:Admindaten">
                                                                     <xs:complexType>
                                                                           <xs:sequence>
                                                                                 <xs:element name="bew:Verarbeitungskennzeichen" type="xs:string"></xs:element>
                                                                                 <xs:element name="bew:Version" type="xs:string"></xs:element>
                                                                                 <xs:element name="bew:LfdNr" type="xs:string"></xs:element>
                                                                           </xs:sequence>
                                                                           <xs:attribute name="xmlns:bew" type="xs:string"></xs:attribute>
                                                                     </xs:complexType>
                                                               </xs:element>
                                                               <xs:element name="bew:Fachliche_Daten">
                                                                     <xs:complexType>
                                                                           <xs:sequence>
                                                                                 <xs:element name="bew:Rehabilitand">
                                                                                       <xs:complexType>
                                                                                             <xs:sequence>
                                                                                                   <xs:element name="bew:Anrede" type="xs:string"></xs:element>
                                                                                                   <xs:element name="bew:Name">
                                                                                                         <xs:complexType>
                                                                                                               <xs:sequence>
                                                                                                                     <xs:element name="bty:Nachname" type="xs:string">
                                                                                                                           <xs:complexType>
                                                                                                                                 <xs:attribute name="xmlns:bty" type="xs:string"></xs:attribute>
                                                                                                                           </xs:complexType>
                                                                                                                     </xs:element>
                                                                                                                     <xs:element name="bty:Vorname" type="xs:string">
                                                                                                                           <xs:complexType>
                                                                                                                                 <xs:attribute name="xmlns:bty" type="xs:string"></xs:attribute>
                                                                                                                           </xs:complexType>
                                                                                                                     </xs:element>
                                                                                                               </xs:sequence>
                                                                                                         </xs:complexType>
                                                                                                   </xs:element>
                                                                                                   <xs:element name="bew:Geschlecht" type="xs:string"></xs:element>
                                                                                                   <xs:element name="bew:Geburtsdatum" type="xs:date"></xs:element>
                                                                                                   <xs:element name="bew:Adresse">
                                                                                                         <xs:complexType>
                                                                                                               <xs:sequence>
                                                                                                                     <xs:element name="bty:Strasse" type="xs:string">
                                                                                                                           <xs:complexType>
                                                                                                                                 <xs:attribute name="xmlns:bty" type="xs:string"></xs:attribute>
                                                                                                                           </xs:complexType>
                                                                                                                     </xs:element>
                                                                                                                     <xs:element name="bty:Hausnummer" type="xs:string">
                                                                                                                           <xs:complexType>
                                                                                                                                 <xs:attribute name="xmlns:bty" type="xs:string"></xs:attribute>
                                                                                                                           </xs:complexType>
                                                                                                                     </xs:element>
                                                                                                                     <xs:element name="bty:Wohnort" type="xs:string">
                                                                                                                           <xs:complexType>
                                                                                                                                 <xs:attribute name="xmlns:bty" type="xs:string"></xs:attribute>
                                                                                                                           </xs:complexType>
                                                                                                                     </xs:element>
                                                                                                                     <xs:element name="bty:PLZ" type="xs:string">
                                                                                                                           <xs:complexType>
                                                                                                                                 <xs:attribute name="xmlns:bty" type="xs:string"></xs:attribute>
                                                                                                                           </xs:complexType>
                                                                                                                     </xs:element>
                                                                                                                     <xs:element name="bty:Laenderkennzeichen" type="xs:string">
                                                                                                                           <xs:complexType>
                                                                                                                                 <xs:attribute name="xmlns:bty" type="xs:string"></xs:attribute>
                                                                                                                           </xs:complexType>
                                                                                                                     </xs:element>
                                                                                                               </xs:sequence>
                                                                                                         </xs:complexType>
                                                                                                   </xs:element>
                                                                                                   <xs:element name="bew:Kommunikation">
                                                                                                         <xs:complexType>
                                                                                                               <xs:sequence>
                                                                                                                     <xs:element name="bty:Telefon" type="xs:string">
                                                                                                                           <xs:complexType>
                                                                                                                                 <xs:attribute name="xmlns:bty" type="xs:string"></xs:attribute>
                                                                                                                           </xs:complexType>
                                                                                                                     </xs:element>
                                                                                                               </xs:sequence>
                                                                                                         </xs:complexType>
                                                                                                   </xs:element>
                                                                                             </xs:sequence>
                                                                                       </xs:complexType>
                                                                                 </xs:element>
                                                                                 <xs:element name="bew:Kosteninformationen">
                                                                                       <xs:complexType>
                                                                                             <xs:sequence>
                                                                                                   <xs:element name="bew:Zuzahlung">
                                                                                                         <xs:complexType>
                                                                                                               <xs:sequence>
                                                                                                                     <xs:element name="bew:Zuzahlungseinzug" type="xs:string"></xs:element>
                                                                                                                     <xs:element name="bew:AnzahlTage" type="xs:string"></xs:element>
                                                                                                                     <xs:element name="bew:Zuzahlungsbetrag" type="xs:string"></xs:element>
                                                                                                               </xs:sequence>
                                                                                                         </xs:complexType>
                                                                                                   </xs:element>
                                                                                             </xs:sequence>
                                                                                       </xs:complexType>
                                                                                 </xs:element>
                                                                                 <xs:element name="bew:Rehainformationen">
                                                                                       <xs:complexType>
                                                                                             <xs:sequence>
                                                                                                   <xs:element name="bew:Rehaart" type="xs:string"></xs:element>
                                                                                             </xs:sequence>
                                                                                       </xs:complexType>
                                                                                 </xs:element>
                                                                                 <xs:element name="bew:Aufnahmedaten">
                                                                                       <xs:complexType>
                                                                                             <xs:sequence>
                                                                                                   <xs:element name="bew:IK_Krankenhaus" type="xs:string"></xs:element>
                                                                                                   <xs:element name="bew:Behandlungsart" type="xs:string"></xs:element>
                                                                                                   <xs:element name="bew:Bewilligungsdiagnosen">
                                                                                                         <xs:complexType>
                                                                                                               <xs:sequence>
                                                                                                                     <xs:element name="bew:Version_ICD" type="xs:string"></xs:element>
                                                                                                                     <xs:element name="bew:Diagnose">
                                                                                                                           <xs:complexType>
                                                                                                                                 <xs:sequence>
                                                                                                                                       <xs:element name="bty:Diagnosenschluessel" type="xs:string">
                                                                                                                                             <xs:complexType>
                                                                                                                                                   <xs:attribute name="xmlns:bty" type="xs:string"></xs:attribute>
                                                                                                                                             </xs:complexType>
                                                                                                                                       </xs:element>
                                                                                                                                 </xs:sequence>
                                                                                                                           </xs:complexType>
                                                                                                                     </xs:element>
                                                                                                               </xs:sequence>
                                                                                                         </xs:complexType>
                                                                                                   </xs:element>
                                                                                                   <xs:element name="bew:Aufnahmedaten">
                                                                                                         <xs:complexType>
                                                                                                               <xs:sequence>
                                                                                                                     <xs:element name="bew:Erfolgt" type="xs:string"></xs:element>
                                                                                                                     <xs:element name="bew:Geplant" type="xs:date"></xs:element>
                                                                                                               </xs:sequence>
                                                                                                         </xs:complexType>
                                                                                                   </xs:element>
                                                                                                   <xs:element name="bew:Indikationsgruppe" type="xs:string"></xs:element>
                                                                                             </xs:sequence>
                                                                                       </xs:complexType>
                                                                                 </xs:element>
                                                                                 <xs:element name="bew:Bewilligungsinformationen">
                                                                                       <xs:complexType>
                                                                                             <xs:sequence>
                                                                                                   <xs:element name="bew:Bewilligungsdatum" type="xs:date"></xs:element>
                                                                                                   <xs:element name="bew:Kostenzusage_gueltig_bis" type="xs:date"></xs:element>
                                                                                             </xs:sequence>
                                                                                       </xs:complexType>
                                                                                 </xs:element>
                                                                                 <xs:element name="bew:Stationaerdaten">
                                                                                       <xs:complexType>
                                                                                             <xs:sequence>
                                                                                                   <xs:element name="bew:Behandlungsabschnitte" type="xs:string"></xs:element>
                                                                                                   <xs:element name="bew:bewilligte_Tage" type="xs:string"></xs:element>
                                                                                             </xs:sequence>
                                                                                       </xs:complexType>
                                                                                 </xs:element>
                                                                           </xs:sequence>
                                                                           <xs:attribute name="xmlns:bew" type="xs:string"></xs:attribute>
                                                                     </xs:complexType>
                                                               </xs:element>
                                                         </xs:sequence>
                                                   </xs:complexType>
                                             </xs:element>
                                       </xs:sequence>
                                 </xs:complexType>
                           </xs:element>
                           <xs:element name="reh:Papieranlage" type="xs:string"></xs:element>
                     </xs:sequence>
                     <xs:attribute name="xmlns:reh" type="xs:string"></xs:attribute>
               </xs:complexType>
         </xs:element>
   </xs:schema>

If you import this XSD file into the XML binding wizard, it will generate a unit that can produce the correct XML for you.

whosrdaddy
  • 11,720
  • 4
  • 50
  • 99
  • As you see here : left side = original ||||||||| right side = new generated file. The namespaces are still missing :-/ its only possible to set a namespace for the whole "Kopfdaten" part for example. https://i.imgur.com/trWqUPU.png – Hidden Apr 14 '15 at 14:25
2

This is an ancient Delphi bug and a problem everyone who wants to use Delphi for high-end programming in a modern environment face. The XML binding wizard tends to crash if it encounters things like @include, so if you have nested namespaces (or external dependencies, like most schemas have these days) you are out of luck. Adding a namespace however is not possible. Under normal circumstances its not needed as the XML parser will resolve the names, but if you have the same identifier used by two files - then it will collide and render the XML useless. You should file a demand to EMB and get them to fix this, like I have done on 2 occations -- perhaps they will wake up and do something this time.

Jon Lennart Aasenden
  • 3,920
  • 2
  • 29
  • 44
  • If you accept my reply then please up the answere or accept it. There is no updates for this problem sadly. I sincerly hope Embarcadero fixes this, but as of date its still there. – Jon Lennart Aasenden Apr 10 '15 at 20:54
  • Currently, on Delphi Tokyo, the wizard still isn't changed. It still has all the described problems and the entry in the bug tracker is still marked as "Open". – rk_cpa Sep 03 '18 at 09:43
2

Just a fast solution, you can make it more pretty

using msxml;

procedure TForm1.bt1Click(Sender: TObject);
var
  Document: DOMDocument;
  RootNode, Node: IXMLDOMNode;
const
  rehNameSpace: WideString = 'reh';
  rehNameSpaceURI: WideString = 'http://www.vdek.com/xml-schema/REH/1.8';
  kodNameSpace: WideString = 'kod';
  kodNameSpaceURI: WideString = 'http://www.vdek.com/xml-schema/KOD/1.2';
begin
  Document := CoDOMDocument60.Create;

  RootNode := Document.createNode(NODE_ELEMENT, rehNameSpace + ':Reha', rehNameSpaceURI);
  Document.appendChild(RootNode);

  Node := Document.createNode(NODE_ELEMENT, rehNameSpace + ':logische_Version', rehNameSpaceURI);
  Node.text := '1.6.0';
  RootNode.appendChild(Node);

  Node := Document.createNode(NODE_ELEMENT, rehNameSpace + ':KV', rehNameSpaceURI);
  RootNode.appendChild(Node);

  RootNode := Node;

  Node := Document.createNode(NODE_ELEMENT, rehNameSpace + ':Kopfdaten', rehNameSpaceURI);
  RootNode.appendChild(Node);
  RootNode := Node;

  Node := Document.createNode(NODE_ELEMENT, kodNameSpace + ':Erstellungsdatum_Uhrzeit', kodNameSpaceURI);
  Node.text := '2014-09-23T15:33:23';
  RootNode.appendChild(Node);

  Node := Document.createNode(NODE_ELEMENT, kodNameSpace + ':Version', kodNameSpaceURI);
  Node.text := '1.2.0';
  RootNode.appendChild(Node);

  Node := Document.createNode(NODE_ELEMENT, kodNameSpace + ':Dateinummer', kodNameSpaceURI);
  Node.text := '000010';
  RootNode.appendChild(Node);

  Node := Document.createNode(NODE_ELEMENT, kodNameSpace + ':Identifikationsdaten', kodNameSpaceURI);
  RootNode.appendChild(Node);

  RootNode := Node;

  mmo1.Text := Document.xml;     // TMemo
end;
kot-da-vinci
  • 1,152
  • 16
  • 30
  • Whats the difference between IXMLDOMNode and IXMLNode? In my actual code i only used IXMLNode – Hidden Apr 17 '15 at 13:51
  • 1
    while this will work, it misses the whole point and that is getting the XML databinding wizard to produce the correct output... – whosrdaddy Apr 17 '15 at 16:51
  • 1
    @Hidden `IXMLNode` is a node interface from delphi's `xml` unit. And `IXMLDOMNode` is a node interface from microsoft's `msxml` library. – kot-da-vinci Apr 22 '15 at 06:09
0

After you did the import via the data binding wizard, you can post-process the generated file. You have to add the third parameter to RegisterChildNode methods and the fourth parameter to the RegisterChildNodes to add the full namespace. After that you have to alter the Getter-methods:

For example you would alter the TXMLKopfdatenType_reh.AfterConstruction from

RegisterChildNode('Erstellungsdatum_Uhrzeit', TErstellungsdatum_UhrzeitTyp_kod)

to

RegisterChildNode('Erstellungsdatum_Uhrzeit', TErstellungsdatum_UhrzeitTyp_kod, 'http://www.vdek.com/xml-schema/KOD/1.2');

and the Getter-Method TXMLKopfdatenType_reh.Get_Erstellungsdatum_Uhrzeit from

Result := ChildNodes['Erstellungsdatum_Uhrzeit'] as IErstellungsdatum_UhrzeitTyp_kod;

to

Result := ChildNodes['kod:Erstellungsdatum_Uhrzeit'] as IErstellungsdatum_UhrzeitTyp_kod;

With this approach you can use the benefits of the XML wizard and correct its mistakes

Raphi1
  • 322
  • 1
  • 9