Changeset 25 for trunk/Packages/Common/UXMLUtils.pas
- Timestamp:
- Sep 10, 2022, 6:54:43 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UXMLUtils.pas
r15 r25 1 1 unit UXMLUtils; 2 3 {$mode delphi}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); … … 21 19 function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string; 22 20 function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime): TDateTime; 21 procedure ReadXMLFileParser(out Doc: TXMLDocument; FileName: string); 23 22 24 23 25 24 implementation 25 26 procedure ReadXMLFileParser(out Doc: TXMLDocument; FileName: string); 27 var 28 Parser: TDOMParser; 29 Src: TXMLInputSource; 30 InFile: TFileStream; 31 begin 32 try 33 InFile := TFileStream.Create(FileName, fmOpenRead); 34 Src := TXMLInputSource.Create(InFile); 35 Parser := TDOMParser.Create; 36 Parser.Options.PreserveWhitespace := True; 37 Parser.Parse(Src, Doc); 38 finally 39 Src.Free; 40 Parser.Free; 41 InFile.Free; 42 end; 43 end; 26 44 27 45 function GetTimeZoneBias: Integer; … … 30 48 TimeZoneInfo: TTimeZoneInformation; 31 49 begin 50 {$push}{$warn 5057 off} 32 51 case GetTimeZoneInformation(TimeZoneInfo) of 33 TIME_ZONE_ID_STANDARD: Result := TimeZoneInfo.Bias + TimeZoneInfo.StandardBias;34 TIME_ZONE_ID_DAYLIGHT: Result := TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias;52 TIME_ZONE_ID_STANDARD: Result := TimeZoneInfo.Bias + TimeZoneInfo.StandardBias; 53 TIME_ZONE_ID_DAYLIGHT: Result := TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias; 35 54 else 36 55 Result := 0; 37 56 end; 57 {$pop} 38 58 end; 39 59 {$ELSE} … … 45 65 function LeftCutString(var Source: string; out Output: string; Delimiter: string; Allowed: string = ''): Boolean; 46 66 var 47 I , J: Integer;67 I: Integer; 48 68 Matched: Boolean; 49 69 begin … … 99 119 if Pos('Z', XMLDateTime) > 0 then 100 120 LeftCutString(XMLDateTime, Part, 'Z'); 101 SecondFraction := StrToFloat('0' + De cimalSeparator + Part);121 SecondFraction := StrToFloat('0' + DefaultFormatSettings.DecimalSeparator + Part); 102 122 Millisecond := Trunc(SecondFraction * 1000); 103 123 end else begin … … 118 138 end; 119 139 120 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString;140 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string; 121 141 const 122 142 Neg: array[Boolean] of string = ('+', '-'); … … 139 159 NewNode: TDOMNode; 140 160 begin 141 NewNode := Node.OwnerDocument.CreateElement( Name);142 NewNode.TextContent := IntToStr(Value);161 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 162 NewNode.TextContent := DOMString(IntToStr(Value)); 143 163 Node.AppendChild(NewNode); 144 164 end; … … 148 168 NewNode: TDOMNode; 149 169 begin 150 NewNode := Node.OwnerDocument.CreateElement( Name);151 NewNode.TextContent := IntToStr(Value);170 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 171 NewNode.TextContent := DOMString(IntToStr(Value)); 152 172 Node.AppendChild(NewNode); 153 173 end; … … 157 177 NewNode: TDOMNode; 158 178 begin 159 NewNode := Node.OwnerDocument.CreateElement( Name);160 NewNode.TextContent := BoolToStr(Value);179 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 180 NewNode.TextContent := DOMString(BoolToStr(Value)); 161 181 Node.AppendChild(NewNode); 162 182 end; … … 166 186 NewNode: TDOMNode; 167 187 begin 168 NewNode := Node.OwnerDocument.CreateElement( Name);169 NewNode.TextContent := Value;188 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 189 NewNode.TextContent := DOMString(Value); 170 190 Node.AppendChild(NewNode); 171 191 end; … … 175 195 NewNode: TDOMNode; 176 196 begin 177 NewNode := Node.OwnerDocument.CreateElement( Name);178 NewNode.TextContent := D ateTimeToXMLTime(Value);197 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 198 NewNode.TextContent := DOMString(DateTimeToXMLTime(Value)); 179 199 Node.AppendChild(NewNode); 180 200 end; … … 185 205 begin 186 206 Result := DefaultValue; 187 NewNode := Node.FindNode( Name);188 if Assigned(NewNode) then 189 Result := StrToInt( NewNode.TextContent);207 NewNode := Node.FindNode(DOMString(Name)); 208 if Assigned(NewNode) then 209 Result := StrToInt(string(NewNode.TextContent)); 190 210 end; 191 211 … … 195 215 begin 196 216 Result := DefaultValue; 197 NewNode := Node.FindNode( Name);198 if Assigned(NewNode) then 199 Result := StrToInt64( NewNode.TextContent);217 NewNode := Node.FindNode(DOMString(Name)); 218 if Assigned(NewNode) then 219 Result := StrToInt64(string(NewNode.TextContent)); 200 220 end; 201 221 … … 205 225 begin 206 226 Result := DefaultValue; 207 NewNode := Node.FindNode( Name);208 if Assigned(NewNode) then 209 Result := StrToBool( NewNode.TextContent);227 NewNode := Node.FindNode(DOMString(Name)); 228 if Assigned(NewNode) then 229 Result := StrToBool(string(NewNode.TextContent)); 210 230 end; 211 231 … … 215 235 begin 216 236 Result := DefaultValue; 217 NewNode := Node.FindNode( Name);218 if Assigned(NewNode) then 219 Result := NewNode.TextContent;237 NewNode := Node.FindNode(DOMString(Name)); 238 if Assigned(NewNode) then 239 Result := string(NewNode.TextContent); 220 240 end; 221 241 … … 226 246 begin 227 247 Result := DefaultValue; 228 NewNode := Node.FindNode( Name);229 if Assigned(NewNode) then 230 Result := XMLTimeToDateTime( NewNode.TextContent);248 NewNode := Node.FindNode(DOMString(Name)); 249 if Assigned(NewNode) then 250 Result := XMLTimeToDateTime(string(NewNode.TextContent)); 231 251 end; 232 252
Note:
See TracChangeset
for help on using the changeset viewer.