- Код: Выделить всё
//----------------------------------------------------------------
procedure TConfig.Package_SaveToXmNode(aParentNode: IXMLNode; aPackageItem:
TPackageItem);
//----------------------------------------------------------------
var
I: Integer;
j: Integer;
oFileItem: TFileItem;
vNode,vNode1: IXMLNode;
s: string;
begin
for I := 0 to aPackageItem.Files.Count - 1 do
begin
oFileItem:=aPackageItem.Files[i];
vNode:=aParentNode.AddChild('file');
vNode.Attributes['filename']:= oFileItem.FileName;
vNode.Attributes['author'] := oFileItem.Author;
vNode.Attributes['email'] := oFileItem.EMail;
s:=DateTimeToStr(oFileItem.DateModify);
vNode.Attributes['date_modify'] := s;
if oFileItem.description<>'' then
vNode.AddChild('description').Text:= oFileItem.description;
for j := 0 to oFileItem.SubFiles.Count - 1 do
vNode.AddChild('file').Attributes['name'] := oFileItem.SubFiles[j];
end;
end;
//----------------------------------------------------------------
procedure TConfig.SaveToXmlFile(aFileName: string);
//----------------------------------------------------------------
//----------------------------------------------------------------
procedure DoSavePackages(aParentNode: IXMLNode);
//----------------------------------------------------------------
var
I: Integer;
vNode: IXMLNode;
begin
for I := 0 to Count - 1 do
begin
vNode:=aParentNode.AddChild('structure');
vNode.Attributes['name']:=Items[i].Name;
Package_SaveToXmNode(vNode, Items[i]);
end;
end;
var
oXmlDocument: TXmlDocument;
vRoot: IXMLNode;
begin
oXmlDocument:=TXmlDocument.Create(Application);
oXmlDocument.Options:=oXmlDocument.Options + [doNodeAutoIndent];
oXmlDocument.Active:=true;
oXmlDocument.Version:='1.0';
// XmlDocument.Encoding:='UTF-8';
oXmlDocument.Encoding:='windows-1251';
vRoot:=oXmlDocument.AddChild('xml');
vRoot.Attributes['xmlns']:='http://www.opengis.net/kml/2.2';
vRoot.Attributes['xmlns:gx']:='http://www.google.com/kml/ext/2.2';
vRoot:=vRoot.AddChild('Document');
DoSavePackages (vRoot);
oXmlDocument.SaveToFile(aFileName);
FreeAndNil(oXmlDocument);
end;
Добавлено спустя 2 часа 24 минуты 50 секунд:
В результате сам сделал:
- Код: Выделить всё
procedure TScriptStorage.SaveLocalXMLRegistry(aFileName: string);
var
oXmlDocument: TXmlDocument;
vRoot,ParentNode,PackageNode,TempNode,Description,FileItemNode,SubFileNode: TDOMNode;
i,d,j: integer;
s: string;
oFileItem: TFileItemEx;
begin
oXmlDocument:=TXmlDocument.Create;
//oXmlDocument.Version:='1.0';
oXmlDocument.Encoding:='UTF-8';
//oXmlDocument.Encoding:='windows-1251';
vRoot:=oXmlDocument.CreateElement('xml');
TDOMElement(vRoot).SetAttribute('xmlns','http://www.opengis.net/kml/2.2');
TDOMElement(vRoot).SetAttribute('xmlns:gx','http://www.opengis.net/kml/2.2');
oXmlDocument.AppendChild(vroot);
vRoot:=oXMLDocument.DocumentElement;
ParentNode:=oXmlDocument.CreateElement('Document');
vRoot.AppendChild(ParentNode);
for i:=0 to count -1 do
begin
PackageNode:=oXmlDocument.CreateElement('structure');
TDOMElement(PackageNode).SetAttribute('name',Items[i].Name);
for d:=0 to Items[i].Files.Count - 1 do
begin
oFileItem:=Items[i].Files.ItemsEx[d];
FileItemNode:=oXMLDocument.CreateElement('file');
TDOMElement(FileItemNode).SetAttribute('filename',oFileItem.FileName);
TDOMElement(FileItemNode).SetAttribute('author',oFileItem.Author);
TDOMElement(FileItemNode).SetAttribute('email',oFileItem.EMail);
TDOMElement(FileItemNode).SetAttribute('version',FloatToStr(oFileItem.Version));
TDOMElement(FileItemNode).SetAttribute('installed',IntToStr(oFileItem.Installed));
s:=DateTimeToStr(oFileItem.DateModify);
TDOMElement(FileItemNode).SetAttribute('date_modify',s);
if oFileItem.description<>'' then
begin
TempNode:=oXMLDocument.CreateElement('description');
Description:=oXMLDocument.CreateTextNode(oFileItem.description);
TempNode.AppendChild(Description);
FileItemNode.AppendChild(TempNode);
end;
for j := 0 to oFileItem.SubFiles.Count - 1 do
begin
SubFileNode:=oXMLDocument.CreateElement('subfile');
TDOMElement(SubFileNode).SetAttribute('filename',oFileItem.SubFiles[j].FileName);
TDOMElement(SubFileNode).SetAttribute('filepath',oFileItem.SubFiles[j].UnpPath);
FileItemNode.AppendChild(SubFileNode);
end;
PackageNode.AppendChild(FileItemNode);
end;
// vRoot.AppendChild(PackageNode);
vRoot.ChildNodes.Item[0].AppendChild(PackageNode);
end;
WriteXMLFile (oXmlDocument,aFileName);
FreeAndNil(oXmlDocument);
end;