Changeset 21 for trunk/Packages/Common/XML.pas
- Timestamp:
- Apr 3, 2025, 10:49:00 PM (13 days ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/XML.pas
r20 r21 1 unit UXMLUtils; 2 3 {$mode delphi} 1 unit XML; 4 2 5 3 interface … … 7 5 uses 8 6 {$IFDEF WINDOWS}Windows,{$ENDIF} 9 Classes, SysUtils, DateUtils, XMLRead, XMLWrite, DOM;7 Classes, SysUtils, DateUtils, DOM, xmlread; 10 8 11 9 function XMLTimeToDateTime(XMLDateTime: string): TDateTime; 12 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString;10 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string; 13 11 procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer); 14 12 procedure WriteInt64(Node: TDOMNode; Name: string; Value: Int64); … … 16 14 procedure WriteString(Node: TDOMNode; Name: string; Value: string); 17 15 procedure WriteDateTime(Node: TDOMNode; Name: string; Value: TDateTime); 16 procedure WriteDouble(Node: TDOMNode; Name: string; Value: Double); 18 17 function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer; 19 18 function ReadInt64(Node: TDOMNode; Name: string; DefaultValue: Int64): Int64; … … 21 20 function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string; 22 21 function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime): TDateTime; 22 function ReadDouble(Node: TDOMNode; Name: string; DefaultValue: Double): Double; 23 procedure ReadXMLFileParser(out Doc: TXMLDocument; FileName: string); 23 24 24 25 25 26 implementation 27 28 function ReadDouble(Node: TDOMNode; Name: string; DefaultValue: Double): Double; 29 var 30 NewNode: TDOMNode; 31 begin 32 Result := DefaultValue; 33 NewNode := Node.FindNode(DOMString(Name)); 34 if Assigned(NewNode) then 35 Result := StrToFloat(string(NewNode.TextContent)); 36 end; 37 38 procedure ReadXMLFileParser(out Doc: TXMLDocument; FileName: string); 39 var 40 Parser: TDOMParser; 41 Src: TXMLInputSource; 42 InFile: TFileStream; 43 begin 44 try 45 InFile := TFileStream.Create(FileName, fmOpenRead); 46 Src := TXMLInputSource.Create(InFile); 47 Parser := TDOMParser.Create; 48 Parser.Options.PreserveWhitespace := True; 49 Parser.Parse(Src, Doc); 50 finally 51 Src.Free; 52 Parser.Free; 53 InFile.Free; 54 end; 55 end; 26 56 27 57 function GetTimeZoneBias: Integer; … … 30 60 TimeZoneInfo: TTimeZoneInformation; 31 61 begin 62 {$push}{$warn 5057 off} 32 63 case GetTimeZoneInformation(TimeZoneInfo) of 33 TIME_ZONE_ID_STANDARD: Result := TimeZoneInfo.Bias + TimeZoneInfo.StandardBias;34 TIME_ZONE_ID_DAYLIGHT: Result := TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias;64 TIME_ZONE_ID_STANDARD: Result := TimeZoneInfo.Bias + TimeZoneInfo.StandardBias; 65 TIME_ZONE_ID_DAYLIGHT: Result := TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias; 35 66 else 36 67 Result := 0; 37 68 end; 69 {$pop} 38 70 end; 39 71 {$ELSE} … … 45 77 function LeftCutString(var Source: string; out Output: string; Delimiter: string; Allowed: string = ''): Boolean; 46 78 var 47 I , J: Integer;79 I: Integer; 48 80 Matched: Boolean; 49 81 begin … … 99 131 if Pos('Z', XMLDateTime) > 0 then 100 132 LeftCutString(XMLDateTime, Part, 'Z'); 101 SecondFraction := StrToFloat('0' + De cimalSeparator + Part);133 SecondFraction := StrToFloat('0' + DefaultFormatSettings.DecimalSeparator + Part); 102 134 Millisecond := Trunc(SecondFraction * 1000); 103 135 end else begin … … 118 150 end; 119 151 120 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString;152 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string; 121 153 const 122 154 Neg: array[Boolean] of string = ('+', '-'); … … 139 171 NewNode: TDOMNode; 140 172 begin 141 NewNode := Node.OwnerDocument.CreateElement( Name);142 NewNode.TextContent := IntToStr(Value);173 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 174 NewNode.TextContent := DOMString(IntToStr(Value)); 143 175 Node.AppendChild(NewNode); 144 176 end; … … 148 180 NewNode: TDOMNode; 149 181 begin 150 NewNode := Node.OwnerDocument.CreateElement( Name);151 NewNode.TextContent := IntToStr(Value);182 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 183 NewNode.TextContent := DOMString(IntToStr(Value)); 152 184 Node.AppendChild(NewNode); 153 185 end; … … 157 189 NewNode: TDOMNode; 158 190 begin 159 NewNode := Node.OwnerDocument.CreateElement( Name);160 NewNode.TextContent := BoolToStr(Value);191 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 192 NewNode.TextContent := DOMString(BoolToStr(Value)); 161 193 Node.AppendChild(NewNode); 162 194 end; … … 166 198 NewNode: TDOMNode; 167 199 begin 168 NewNode := Node.OwnerDocument.CreateElement( Name);169 NewNode.TextContent := Value;200 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 201 NewNode.TextContent := DOMString(Value); 170 202 Node.AppendChild(NewNode); 171 203 end; … … 175 207 NewNode: TDOMNode; 176 208 begin 177 NewNode := Node.OwnerDocument.CreateElement(Name); 178 NewNode.TextContent := DateTimeToXMLTime(Value); 209 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 210 NewNode.TextContent := DOMString(DateTimeToXMLTime(Value)); 211 Node.AppendChild(NewNode); 212 end; 213 214 procedure WriteDouble(Node: TDOMNode; Name: string; Value: Double); 215 var 216 NewNode: TDOMNode; 217 begin 218 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 219 NewNode.TextContent := DOMString(FloatToStr(Value)); 179 220 Node.AppendChild(NewNode); 180 221 end; … … 185 226 begin 186 227 Result := DefaultValue; 187 NewNode := Node.FindNode( Name);188 if Assigned(NewNode) then 189 Result := StrToInt( NewNode.TextContent);228 NewNode := Node.FindNode(DOMString(Name)); 229 if Assigned(NewNode) then 230 Result := StrToInt(string(NewNode.TextContent)); 190 231 end; 191 232 … … 195 236 begin 196 237 Result := DefaultValue; 197 NewNode := Node.FindNode( Name);198 if Assigned(NewNode) then 199 Result := StrToInt64( NewNode.TextContent);238 NewNode := Node.FindNode(DOMString(Name)); 239 if Assigned(NewNode) then 240 Result := StrToInt64(string(NewNode.TextContent)); 200 241 end; 201 242 … … 205 246 begin 206 247 Result := DefaultValue; 207 NewNode := Node.FindNode( Name);208 if Assigned(NewNode) then 209 Result := StrToBool( NewNode.TextContent);248 NewNode := Node.FindNode(DOMString(Name)); 249 if Assigned(NewNode) then 250 Result := StrToBool(string(NewNode.TextContent)); 210 251 end; 211 252 … … 215 256 begin 216 257 Result := DefaultValue; 217 NewNode := Node.FindNode( Name);218 if Assigned(NewNode) then 219 Result := NewNode.TextContent;258 NewNode := Node.FindNode(DOMString(Name)); 259 if Assigned(NewNode) then 260 Result := string(NewNode.TextContent); 220 261 end; 221 262 … … 226 267 begin 227 268 Result := DefaultValue; 228 NewNode := Node.FindNode( Name);229 if Assigned(NewNode) then 230 Result := XMLTimeToDateTime( NewNode.TextContent);269 NewNode := Node.FindNode(DOMString(Name)); 270 if Assigned(NewNode) then 271 Result := XMLTimeToDateTime(string(NewNode.TextContent)); 231 272 end; 232 273 233 274 end. 234
Note:
See TracChangeset
for help on using the changeset viewer.