Einzelnen Beitrag anzeigen

Benutzerbild von cherry
cherry

Registriert seit: 14. Nov 2005
561 Beiträge
 
RAD-Studio 2009 Ent
 
#12

Re: Attribute die ich gar nicht explizit erstellt habe

  Alt 27. Mai 2007, 11:02
@Marabu

VIELEN DANK, hat bestens geklappt. Ich hab meine Datei jetzt so erzeugt, ist das nun Korrekt oder
würdest du noch etwas anders machen. Ich werde diese Prozedur dann in eine DLL packen, so dass ich sie später
auch für andere Programme verwenden kann...

Delphi-Quellcode:
// XML DATEI ERSTELLEN
procedure TForm1.Act_create_XMLExecute(Sender: TObject; filename: String; vUserName,
  vSwSystemID, vSwSystemName, vSwSystemID_2, vTransactionID, vTransactionCase,
  vTransactionDate, vTransactionAcknowledge, vTransactionDescription,
  vMutationType, vReferenceID, vReferenceID2, vReferenceType, vExtPosID,
  vEventID, vRedundancyCheck, vName, vLegalForm, aLegalForm, vFormationType,
  aFormationType, vFormationDate, vAddressReferenceID, vAddressTypeOf,
  aAddressTypeOf, vAdditionalStreetPosition, vValidFrom, vNote, vStreet,
  vAdditionalStreet, aAdditionalStreet, vHouseNumber,
  vAdditionalHouseNumber, aAdditionalHouseNumber, vCityID, vZipCodeID,
  vZipCode, vTown, vCountry, aCountry, vLocality, aLocality, vZipCodeAddOn:
  WideString);
var
  xmlDoc : msDOMDocument;
  instr: IXMLDOMProcessingInstruction;
  nsDef: WideString;
  root, nPackage, nSender, nUser, nUserName, nSwSystemID, nSwSystemName,
  nReceiver, nSwSystemID_2, nTransaction, nTransactionID, nTransactionCase,
  nTransactionDate, nTransactionAcknowledge, nTransactionDescription,
  nSubjectEvent, nMutationType, nReferenceID, nReferenceID2, nReferenceType,
  nExtPosID, nEventID, nRedundancyCheck, nSubject, nName, nNotNaturalPerson,
  nLegalForm, nFormationType, nFormationDate, nAddress, nAddressReferenceID,
  nAddressTypeOf, nAdditionalStreetPosition, nValidFrom, nNote, nPlace, nStreet,
  nAdditionalStreet, nHouseNumber, nAdditionalHouseNumber, nCity, nCityID,
  nZipCodeID, nZipCode, nTown, nCountry, nLocality, nZipCodeAddOn: IXMLDOMNode;
begin
  nsDef := 'http://innosolv.ch/namespace/isag';

  // Microsoft Document Object Model - Document erstellen
  xmlDoc := CoDOMDocument40.Create;

  // (Rootnode) Wurzelelement erzeugen
  root := xmlDoc.createElement('subjectData');

  // Prolog mit Steueranweisungen (Processing instructions)
  instr := xmlDoc.createProcessingInstruction('xml', 'version="1.0" encoding="utf-8"');
  xmlDoc.appendChild(instr);

  // Rootelement mit Namespaces definieren
  with root as IXMLDOMElement do
  begin
    setAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
    setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchame-instance');
    setAttribute('xmlns', nsDef);
  end;

  // Rootelement an Dokument anfügen
  xmlDoc.appendChild(root);

  // Nachfolgend wird der ganze Baum mit allen relevanten Namespaces erstellt.

    nPackage := root.appendChild(xmlDoc.createNode(NODE_ELEMENT,'package',nsDef));
      nSender := nPackage.appendChild(xmlDoc.createNode(NODE_ELEMENT,'sender',nsDef));
        nUser := nSender.appendChild(xmlDoc.createNode(NODE_ELEMENT,'user',nsDef));
          nUserName := nUser.appendChild(xmlDoc.createNode(NODE_ELEMENT,'userName',nsDef));
          nUserName.text := vUserName;

        nSwSystemID := nSender.appendChild(xmlDoc.createNode(NODE_ELEMENT,'swSystemID',nsDef));
        nSwSystemID.text := vSwSystemID;
        nSwSystemName := nSender.appendChild(xmlDoc.createNode(NODE_ELEMENT,'swSystemName',nsDef));
        nSwSystemName.text := vSwSystemName;

      nReceiver := nPackage.appendChild(xmlDoc.createNode(NODE_ELEMENT,'receiver',nsDef));
        nSwSystemID_2 := nReceiver.appendChild(xmlDoc.createNode(NODE_ELEMENT,'swSystemID',nsDef));
        nSwSystemID_2.text := vSwSystemID_2;

      nTransaction := nPackage.appendChild(xmlDoc.createNode(NODE_ELEMENT,'transaction',nsDef));
        nTransactionID := nTransaction.appendChild(xmlDoc.createNode(NODE_ELEMENT,'transactionID',nsDef));
        nTransactionID.text := vTransactionID;
        nTransactionCase := nTransaction.appendChild(xmlDoc.createNode(NODE_ELEMENT,'transactionCase',nsDef));
        nTransactionCase.text := vTransactionCase;
        nTransactionDate := nTransaction.appendChild(xmlDoc.createNode(NODE_ELEMENT,'transactionDate',nsDef));
        nTransactionDate.text := vTransactionDate;
        nTransactionAcknowledge := nTransaction.appendChild(xmlDoc.createNode(NODE_ELEMENT,'transactionAcknowledge',nsDef));
        nTransactionAcknowledge.text := vTransactionAcknowledge;
        nTransactionDescription := nTransaction.appendChild(xmlDoc.createNode(NODE_ELEMENT,'transactionDescription',nsDef));
        nTransactionDescription.text := vTransactionDescription;

    nSubjectEvent := root.appendChild(xmlDoc.createNode(NODE_ELEMENT,'subjectEvent',nsDef));
      nMutationType := nSubjectEvent.appendChild(xmlDoc.createNode(NODE_ELEMENT,'mutationType',nsDef));
      nMutationType.text := vMutationType;
      nReferenceID := nSubjectEvent.appendChild(xmlDoc.createNode(NODE_ELEMENT,'referenceID',nsDef));
      nReferenceID.text := vReferenceID;
      nReferenceID2 := nSubjectEvent.appendChild(xmlDoc.createNode(NODE_ELEMENT,'referenceID2',nsDef));
      nReferenceID2.text := vReferenceID;
      nReferenceType := nSubjectEvent.appendChild(xmlDoc.createNode(NODE_ELEMENT,'referenceType',nsDef));
      nReferenceType.text := vReferenceType;
      nExtPosID := nSubjectEvent.appendChild(xmlDoc.createNode(NODE_ELEMENT,'extPosID',nsDef));
      nExtPosID.text := vExtPosID;
      nRedundancyCheck := nSubjectEvent.appendChild(xmlDoc.createNode(NODE_ELEMENT,'redundancyCheck',nsDef));
      nRedundancyCheck.text := vRedundancyCheck;

      nSubject := nSubjectEvent.appendChild(xmlDoc.createNode(NODE_ELEMENT,'subject',nsDef));
        nName := nSubject.appendChild(xmlDoc.createNode(NODE_ELEMENT,'name',nsDef));
        nName.text := vName;

        nNotNaturalPerson := nSubject.appendChild(xmlDoc.createNode(NODE_ELEMENT,'notNaturalPerson',nsDef));
          nLegalForm := nNotNaturalPerson .appendChild(xmlDoc.createNode(NODE_ELEMENT,'legalForm',nsDef));
          with nLegalForm as IXMLDOMElement do
          begin
            text := vLegalForm;
            setAttribute('rvcd', aLegalForm);
          end;
          nFormationType := nNotNaturalPerson .appendChild(xmlDoc.createNode(NODE_ELEMENT,'formationType',nsDef));
          with nLegalForm as IXMLDOMElement do
          begin
            text := vFormationType;
            setAttribute('rvcd', aFormationType);
          end;
          nFormationDate := nNotNaturalPerson .appendChild(xmlDoc.createNode(NODE_ELEMENT,'formationDate',nsDef));
          nFormationDate.text := vFormationDate;

        nAddress := nSubject.appendChild(xmlDoc.createNode(NODE_ELEMENT,'address',nsDef));
          nAddressReferenceID := nAddress.appendChild(xmlDoc.createNode(NODE_ELEMENT,'addressReferenceID',nsDef));
          nAddressReferenceID.text := vAddressReferenceID;
          nAddressTypeOf := nAddress.appendChild(xmlDoc.createNode(NODE_ELEMENT,'addressTypeOf',nsDef));
          with nAddressTypeOf as IXMLDOMElement do
          begin
            text := vAddressTypeOf;
            setAttribute('rvcd', aAddressTypeOf);
          end;
          nAdditionalStreetPosition := nAddress.appendChild(xmlDoc.createNode(NODE_ELEMENT,'additionalStreetPosition',nsDef));
          nAdditionalStreetPosition.text := vAdditionalStreetPosition;
          nValidFrom := nAddress.appendChild(xmlDoc.createNode(NODE_ELEMENT,'validFrom',nsDef));
          nValidFrom.text := vValidFrom;
          nNote := nAddress.appendChild(xmlDoc.createNode(NODE_ELEMENT,'note',nsDef));
          nNote.text := vNote;

          nPlace := nAddress.appendChild(xmlDoc.createNode(NODE_ELEMENT,'place',nsDef));
            nStreet := nPlace.appendChild(xmlDoc.createNode(NODE_ELEMENT,'street',nsDef));
            nStreet.text := vStreet;
            nAdditionalStreet := nPlace.appendChild(xmlDoc.createNode(NODE_ELEMENT,'additionalStreet',nsDef));
            with nAdditionalStreet as IXMLDOMElement do
            begin
              text := vAdditionalStreet;
              setAttribute('xsi:nil', aAdditionalStreet);
            end;
            nHouseNumber := nPlace.appendChild(xmlDoc.createNode(NODE_ELEMENT,'houseNumber',nsDef));
            nHouseNumber.text := vHouseNumber;
            nAdditionalHouseNumber := nPlace.appendChild(xmlDoc.createNode(NODE_ELEMENT,'additionalHouseNumber',nsDef));
            with nAdditionalHouseNumber as IXMLDOMElement do
            begin
              text := vAdditionalHouseNumber;
              setAttribute('xsi:nil', aAdditionalHouseNumber);
            end;

              nCity := nPlace.appendChild(xmlDoc.createNode(NODE_ELEMENT,'city',nsDef));
                nCityID := nCity.appendChild(xmlDoc.createNode(NODE_ELEMENT,'cityID',nsDef));
                nCityID.text := vCityID;
                nZipCodeID := nCity.appendChild(xmlDoc.createNode(NODE_ELEMENT,'zipCodeID',nsDef));
                nZipCodeID.text := vZipCodeID;
                nZipCode := nCity.appendChild(xmlDoc.createNode(NODE_ELEMENT,'zipCode',nsDef));
                nZipCode.text := vZipCode;
                nTown := nCity.appendChild(xmlDoc.createNode(NODE_ELEMENT,'town',nsDef));
                nTown.text := vTown;
                nCountry := nCity.appendChild(xmlDoc.createNode(NODE_ELEMENT,'country',nsDef));
                with nCountry as IXMLDOMElement do
                begin
                  text := vCountry;
                  setAttribute('rvcd', aCountry);
                end;
                nLocality := nCity.appendChild(xmlDoc.createNode(NODE_ELEMENT,'locality',nsDef));
                with nLocality as IXMLDOMElement do
                begin
                  text := vLocality;
                  setAttribute('xsi:nil', aLocality);
                end;
                nZipCodeAddOn := nCity.appendChild(xmlDoc.createNode(NODE_ELEMENT,'zipCodeAddOn',nsDef));

  // XML - Dokument wird gespeichert.
  xmlDoc.save(filename);

end;

Grüsse Cherry
Ist das nur mein Gefühl, oder ist die ganze Welt verrückt geworden!?
  Mit Zitat antworten Zitat