Changeset 233 for branches/xpascal/Generators/GeneratorXml.pas
- Timestamp:
- Jun 26, 2023, 6:08:23 PM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/xpascal/Generators/GeneratorXml.pas
r232 r233 11 11 TGeneratorXml = class(TGenerator) 12 12 private 13 procedure GenerateNodes(SourceNodes: TSourceNodeList<TSourceNode>); 14 procedure GenerateNode(SourceNode: TSourceNode); 13 procedure GenerateNodes(SourceNodes: TSourceNodeList<TSourceNode>; 14 NodeName: string); 15 procedure GenerateNode(SourceNode: TSourceNode; NodeName: string); 15 16 public 16 17 procedure Generate; override; … … 26 27 { TGeneratorXml } 27 28 28 procedure TGeneratorXml.GenerateNodes(SourceNodes: TSourceNodeList<TSourceNode>); 29 procedure TGeneratorXml.GenerateNodes(SourceNodes: TSourceNodeList<TSourceNode>; 30 NodeName: string); 29 31 var 30 32 I: Integer; … … 32 34 for I := 0 to SourceNodes.Count - 1 do begin 33 35 if SourceNodes[I] is TSourceNode then begin 34 GenerateNode(TSourceNode(SourceNodes[I]) );36 GenerateNode(TSourceNode(SourceNodes[I]), NodeName); 35 37 end else raise Exception.Create(SUnsupportedNodeType); 36 38 end; 37 39 end; 38 40 39 procedure TGeneratorXml.GenerateNode(SourceNode: TSourceNode );41 procedure TGeneratorXml.GenerateNode(SourceNode: TSourceNode; NodeName: string); 40 42 var 41 43 I: Integer; … … 45 47 begin 46 48 if SourceNode is TSourceNode then begin 47 AddTextLine('<' + SourceNode.ClassName + '>');49 AddTextLine('<' + NodeName + '>'); 48 50 Indent := Indent + 1; 49 51 for I := 0 to SourceNode.FieldsCount - 1 do begin 50 52 Field := SourceNode.GetField(I); 51 if Field.DataType = dtObject then begin 52 Obj := SourceNode.GetValueObject(I); 53 if Obj is TSourceNode then 54 GenerateNode(TSourceNode(Obj)); 55 end else 56 if Field.DataType = dtList then begin 57 SourceNode.GetValue(I, List); 58 GenerateNodes(List); 59 end else 60 if Field.DataType = dtString then begin 61 AddTextLine('<' + Field.Name + '>' + SourceNode.GetValueString(I) + '<' + Field.Name + '>'); 53 try 54 if Field.DataType = dtObject then begin 55 Obj := SourceNode.GetValueObject(I); 56 if Obj is TSourceNode then 57 GenerateNode(TSourceNode(Obj), Field.Name); 58 end else 59 if Field.DataType = dtList then begin 60 SourceNode.GetValue(I, List); 61 if List.Count > 0 then 62 GenerateNodes(List, Field.Name); 63 end else 64 if Field.DataType = dtString then begin 65 if SourceNode.GetValueString(I) <> '' then 66 AddTextLine('<' + Field.Name + '>' + SourceNode.GetValueString(I) + 67 '</' + Field.Name + '>'); 68 end; 69 finally 70 Field.Free; 62 71 end; 63 Field.Free;64 72 end; 65 73 Indent := Indent - 1; 66 AddTextLine('</' + SourceNode.ClassName + '>');74 AddTextLine('</' + NodeName + '>'); 67 75 end else 68 76 raise Exception.Create(SUnsupportedNodeType); … … 71 79 procedure TGeneratorXml.Generate; 72 80 begin 73 GenerateNode(Prog); 81 AddTextLine('<?xml version="1.0" encoding="UTF-8"?>'); 82 GenerateNode(Prog, 'Program'); 74 83 end; 75 84
Note:
See TracChangeset
for help on using the changeset viewer.