Hallo.
ich verwende obenXML
Das Problem was ich nu habe
ich wil eine
XML speichern/erstellen die so aussieht
XML-Code:
<?
xml version="1.0" encoding="UTF-8"?>
<daten name="MEINE DATEN">
<bestand name="X1">
<regal dat="1a">CD1</regal>
<regal dat="1b">CD2</regal>
<regal dat="1c">CD3</regal>
<regal dat="1d">CD4</regal>
<regal dat="1e">CD5</regal>
</bestand>
<bestand name="X2">
<regal dat="2a">VH1</regal>
<regal dat="2b">VH2</regal>
</bestand>
<bestand name="X3">
<regal dat="3a">DC1</regal>
</bestand>
</daten>
Der Haken es sind die Inhalte "<regal dat="3a">DC1</regal>" variable unterschiedliche anzahl... (for scheife muss genutz werde)...
Wer kann mir dabei helfen??? Denn ich verzweifel solangsma auch was die Formatierung angeht....
MEIN Versuch bzw. die ersten Schritte. Aber das funzt ja hinten und vorne nicht....
Delphi-Quellcode:
procedure TFormular1.Button1Click(Sender: TObject);
var
FDoc: TDomDocument;
FNodeElement: TDomElement;
FNodeText: TDomText;
FNodeComment: TDomComment;
s: string;
Stream: TFileStream;
node: TDOMElement;
i, u: Integer;
K: TDomNodeList;
begin
FDoc := TDomDocument.Create(DomImplementation1);
FNodeElement := TDomElement.Create(FDoc, 'daten');
FDoc.AppendChild(FNodeElement);
FNodeText := TDomText.Create(FDoc);
FNodeText.NodeValue := #10#32#32;
FDoc.FindFirstChildElement.AppendChild(FNodeText);
with FDoc.FindFirstChildElement do
begin
SetAttribute('name', 'MEIN DATEN');
end;
FNodeElement := TDomElement.Create(FDoc, 'bestand');
FDoc.FindFirstChildElement.AppendChild(FNodeElement);
FNodeText := TDomText.Create(FDoc);
FNodeText.NodeValue := #10#32#32;
FDoc.FindFirstChildElement.ChildNodes.Item(1).AppendChild(FNodeText);
FNodeElement := TDomElement.Create(FDoc, 'bestand');
FDoc.FindFirstChildElement.AppendChild(FNodeElement);
FNodeText := TDomText.Create(FDoc);
FNodeText.NodeValue := #10#32#32;
FDoc.FindFirstChildElement.ChildNodes.Item(2).AppendChild(FNodeText);
u := 1;
for i := 0 to 10 - 1 do
begin
FNodeElement := TDomElement.Create(FDoc, 'regal');
FDoc.FindFirstChildElement.ChildNodes.Item(1).AppendChild(FNodeElement);
with TDomElement(FDoc.GetElementsByTagName('bestand').Item(0).ChildNodes.Item(u)) do
begin
SetAttribute('dat', 'X' + IntToStr(i));
end;
u := u + 2;
FNodeText := TDomText.Create(FDoc);
FNodeText.NodeValue := #10#32#32#32#32;
FDoc.FindFirstChildElement.ChildNodes.Item(1).AppendChild(FNodeText);
FNodeText := TDomCDATASection.Create(FDoc);
FNodeText.AppendData( 'CD' + IntToStr(i));
FDoc.GetElementsByTagName('regal').Item(i).AppendChild(FNodeText);
end;
FNodeText := TDomText.Create(FDoc);
FNodeText.NodeValue := #10;
FDoc.FindLastChildElement.AppendChild(FNodeText);
Stream := TFileStream.Create('test.xml', fmCreate);
DomToXmlParser1.WriteToStream(FDoc, 'UTF-8', Stream);
Stream.Free;
FDoc.Free;
end;