Changeset 24 for branches/lazarus/Common/UXmlClasses.pas
- Timestamp:
- Sep 8, 2010, 4:17:21 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/lazarus/Common/UXmlClasses.pas
r23 r24 5 5 interface 6 6 7 uses Classes, SysUtils, Contnrs, StrUtils ;7 uses Classes, SysUtils, Contnrs, StrUtils, UStringListEx; 8 8 9 9 type 10 TStringListEx = class(TStringList)11 public12 procedure AddNameValue(Name, Value: string);13 end;14 15 10 TXmlElement = class 16 11 private … … 31 26 function GetAsString: string; override; 32 27 public 33 EndTagSymbol: Char; 34 TagName: string; 28 EndTagSymbol: string; 29 ShringEmpty: Boolean; 30 Name: string; 35 31 Attributes: TStringListEx; 36 SubElements: T List; // of TXmlElement;32 SubElements: TObjectList; // of TXmlElement; 37 33 constructor Create; 38 34 destructor Destroy; override; … … 41 37 TXmlDocument = class 42 38 private 39 MainTag: TXmlTag; 43 40 function FormatStructure(Text: string): string; 44 41 function GetAsString: string; 45 42 public 46 43 Formated: Boolean; 47 MainTag: TXmlTag;48 44 Content: TXmlTag; 49 45 XmlVersion: string; … … 60 56 constructor TXmlTag.Create; 61 57 begin 58 ShringEmpty := True; 62 59 Attributes := TStringListEx.Create; 63 60 Attributes.NameValueSeparator := '='; 64 SubElements := T List.Create;61 SubElements := TObjectList.Create; 65 62 EndTagSymbol := '/'; 66 63 end; 67 64 68 65 destructor TXmlTag.Destroy; 69 var70 I: Integer;71 66 begin 72 67 Attributes.Free; 73 for I := 0 to SubElements.Count - 1 do TXmlElement(SubElements[I]).Free;74 68 SubElements.Free; 75 69 inherited; … … 90 84 AttributesText := AttributesText + ' ' + Attributes.Names[I] + '="' + Attributes.ValueFromIndex[I] + '"'; 91 85 92 if TagName <> '' then begin93 if Content <> ''then94 Result := '<' + TagName + AttributesText + '>' + Content + '<' + EndTagSymbol + TagName + '>'95 else Result := '<' + TagName + AttributesText + EndTagSymbol + '>';86 if Name <> '' then begin 87 if (Content <> '') or not ShringEmpty then 88 Result := '<' + Name + AttributesText + '>' + Content + '<' + EndTagSymbol + Name + '>' 89 else Result := '<' + Name + AttributesText + EndTagSymbol + '>'; 96 90 end else Result := Content; 97 91 end; … … 116 110 begin 117 111 inherited; 118 Encoding := ' windows-1250';112 Encoding := 'utf-8'; 119 113 XmlVersion := '1.0'; 120 114 MainTag := TXmlTag.Create; 121 115 with MainTag do begin 122 TagName := '?xml';116 Name := '?xml'; 123 117 EndTagSymbol := '?'; 124 Attributes.Add ('version=1.0');125 Attributes.Add ('encoding=windows-1250');118 Attributes.AddNameValue('version', '1.0'); 119 Attributes.AddNameValue('encoding', 'utf-8'); 126 120 end; 127 121 Content := TXmlTag.Create; … … 172 166 function TXmlDocument.GetAsString: string; 173 167 begin 174 Result := MainTag.AsString + 175 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' 176 + Content.AsString; 168 Result := MainTag.AsString + Content.AsString; 177 169 if Formated then Result := FormatStructure(Result); 178 170 end; 179 171 180 { TStringListEx }181 182 procedure TStringListEx.AddNameValue(Name, Value: string);183 begin184 Add(Name + NameValueSeparator + Value);185 end;186 187 172 end.
Note:
See TracChangeset
for help on using the changeset viewer.