AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

xml file erstellen

Ein Thema von khh · begonnen am 22. Jun 2015 · letzter Beitrag vom 24. Jun 2015
 
CCRDude

Registriert seit: 9. Jun 2011
678 Beiträge
 
FreePascal / Lazarus
 
#15

AW: xml file erstellen

  Alt 23. Jun 2015, 12:01
Auch wenn ich der Meinung bin, dass man aus einem Beispiel, das das eine erzeugt, auch was hinkriegen sollte - weil's nur fünf Minuten waren hier ein Beispiel:

Delphi-Quellcode:
// https://en.wikipedia.org/wiki/Microsoft_Office_XML_formats
// http://www.delphipraxis.net/185583-xml-file-erstellen-2.html

program ExcelXMLOutputDemo;

uses
   SysUtils,
   DOM,
   XMLWrite;

   procedure CreateXML(const AFilename: string);
   var
      doc: TXMLDocument;

      function AddTextNode(AParentNode: TDOMNode; ANodeName, ATextValue: DOMString): TDOMNode;
      begin
         Result := doc.CreateElement(ANodeName);
         AParentNode.AppendChild(Result);
         Result.AppendChild(doc.CreateTextNode(ATextValue));
      end;

   var
      nRoot, nDocProperties, nDocSettings: TDOMNode;
   begin
      doc := TXMLDocument.Create;
      try
         doc.XMLVersion := '1.0';
         doc.AppendChild(doc.CreateProcessingInstruction('mso-application', 'progid="Excel.Sheet"'));

         nRoot := doc.CreateElement('Workbook');
         TDOMElement(nRoot).SetAttribute('xmlns', 'urn:schemas-microsoft-com:office:spreadsheet');
         TDOMElement(nRoot).SetAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
         TDOMElement(nRoot).SetAttribute('xmlns:x', 'urn:schemas-microsoft-com:office:excel');
         TDOMElement(nRoot).SetAttribute('xmlns:ss', 'urn:schemas-microsoft-com:office:spreadsheet');
         TDOMElement(nRoot).SetAttribute('xmlns:html', 'http://www.w3.org/TR/REC-html40');
         doc.AppendChild(nRoot);

         nDocProperties := doc.CreateElement('DocumentProperties');
         TDOMElement(nDocProperties).SetAttribute('xmlns', 'urn:schemas-microsoft-com:office:office');
         nRoot.AppendChild(nDocProperties);

         AddTextNode(nDocProperties, 'Author', 'CCRDude');
         AddTextNode(nDocProperties, 'LastAuthor', 'CCRDude');
         AddTextNode(nDocProperties, 'Created', FormatDateTime('yyyy-mm-dd', Now) + 'T' + FormatDateTime('hh:nn:ss', Now) + 'Z');
         AddTextNode(nDocProperties, 'Version', '15.0');

         nDocSettings := doc.CreateElement('OfficeDocumentSettings');
         TDOMElement(nDocSettings).SetAttribute('xmlns', 'urn:schemas-microsoft-com:office:office');
         nRoot.AppendChild(nDocSettings);

         nDocSettings.AppendChild(doc.CreateElement('AllowPNG'));

         WriteXML(doc, AFilename);
      finally
         doc.Free;
      end;
   end;

begin
   CreateXML('C:\Tests\excel.xml');
end.
Ergibt:

Code:
<?xml version="1.0" encoding="utf-8"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
  <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
    <Author>CCRDude</Author>
    <LastAuthor>CCRDude</LastAuthor>
    <Created>2015-06-23T12:57:52Z</Created>
    <Version>15.0</Version>
  </DocumentProperties>
  <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
    <AllowPNG/>
  </OfficeDocumentSettings>
</Workbook>
In dem Beispiel dürfte alles drin sein - von Processing Instructions über Nodes (auch leeren), Text Nodes und Attributen.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:00 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz