Changeset 38 for trunk/Components/Common/UXMLUtils.pas
- Timestamp:
- Apr 18, 2019, 3:34:38 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Components/Common/UXMLUtils.pas
r34 r38 7 7 uses 8 8 {$IFDEF WINDOWS}Windows,{$ENDIF} 9 Classes, SysUtils, DateUtils, XMLRead, XMLWrite, DOM;9 Classes, SysUtils, DateUtils, DOM, xmlread; 10 10 11 11 function XMLTimeToDateTime(XMLDateTime: string): TDateTime; 12 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString;12 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string; 13 13 procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer); 14 14 procedure WriteInt64(Node: TDOMNode; Name: string; Value: Int64); … … 21 21 function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string; 22 22 function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime): TDateTime; 23 procedure ReadXMLFileParser(out Doc: TXMLDocument; FileName: string); 23 24 24 25 25 26 implementation 27 28 procedure ReadXMLFileParser(out Doc: TXMLDocument; FileName: string); 29 var 30 Parser: TDOMParser; 31 Src: TXMLInputSource; 32 InFile: TFileStream; 33 begin 34 try 35 InFile := TFileStream.Create(FileName, fmOpenRead); 36 Src := TXMLInputSource.Create(InFile); 37 Parser := TDOMParser.Create; 38 Parser.Options.PreserveWhitespace := True; 39 Parser.Parse(Src, Doc); 40 finally 41 Src.Free; 42 Parser.Free; 43 InFile.Free; 44 end; 45 end; 26 46 27 47 function GetTimeZoneBias: Integer; … … 30 50 TimeZoneInfo: TTimeZoneInformation; 31 51 begin 52 {$push}{$warn 5057 off} 32 53 case GetTimeZoneInformation(TimeZoneInfo) of 33 TIME_ZONE_ID_STANDARD: Result := TimeZoneInfo.Bias + TimeZoneInfo.StandardBias;34 TIME_ZONE_ID_DAYLIGHT: Result := TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias;54 TIME_ZONE_ID_STANDARD: Result := TimeZoneInfo.Bias + TimeZoneInfo.StandardBias; 55 TIME_ZONE_ID_DAYLIGHT: Result := TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias; 35 56 else 36 57 Result := 0; 37 58 end; 59 {$pop} 38 60 end; 39 61 {$ELSE} … … 45 67 function LeftCutString(var Source: string; out Output: string; Delimiter: string; Allowed: string = ''): Boolean; 46 68 var 47 I , J: Integer;69 I: Integer; 48 70 Matched: Boolean; 49 71 begin … … 99 121 if Pos('Z', XMLDateTime) > 0 then 100 122 LeftCutString(XMLDateTime, Part, 'Z'); 101 SecondFraction := StrToFloat('0' + De cimalSeparator + Part);123 SecondFraction := StrToFloat('0' + DefaultFormatSettings.DecimalSeparator + Part); 102 124 Millisecond := Trunc(SecondFraction * 1000); 103 125 end else begin … … 118 140 end; 119 141 120 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString;142 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string; 121 143 const 122 144 Neg: array[Boolean] of string = ('+', '-'); … … 139 161 NewNode: TDOMNode; 140 162 begin 141 NewNode := Node.OwnerDocument.CreateElement( Name);142 NewNode.TextContent := IntToStr(Value);163 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 164 NewNode.TextContent := DOMString(IntToStr(Value)); 143 165 Node.AppendChild(NewNode); 144 166 end; … … 148 170 NewNode: TDOMNode; 149 171 begin 150 NewNode := Node.OwnerDocument.CreateElement( Name);151 NewNode.TextContent := IntToStr(Value);172 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 173 NewNode.TextContent := DOMString(IntToStr(Value)); 152 174 Node.AppendChild(NewNode); 153 175 end; … … 157 179 NewNode: TDOMNode; 158 180 begin 159 NewNode := Node.OwnerDocument.CreateElement( Name);160 NewNode.TextContent := BoolToStr(Value);181 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 182 NewNode.TextContent := DOMString(BoolToStr(Value)); 161 183 Node.AppendChild(NewNode); 162 184 end; … … 166 188 NewNode: TDOMNode; 167 189 begin 168 NewNode := Node.OwnerDocument.CreateElement( Name);169 NewNode.TextContent := Value;190 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 191 NewNode.TextContent := DOMString(Value); 170 192 Node.AppendChild(NewNode); 171 193 end; … … 175 197 NewNode: TDOMNode; 176 198 begin 177 NewNode := Node.OwnerDocument.CreateElement( Name);178 NewNode.TextContent := D ateTimeToXMLTime(Value);199 NewNode := Node.OwnerDocument.CreateElement(DOMString(Name)); 200 NewNode.TextContent := DOMString(DateTimeToXMLTime(Value)); 179 201 Node.AppendChild(NewNode); 180 202 end; … … 185 207 begin 186 208 Result := DefaultValue; 187 NewNode := Node.FindNode( Name);188 if Assigned(NewNode) then 189 Result := StrToInt( NewNode.TextContent);209 NewNode := Node.FindNode(DOMString(Name)); 210 if Assigned(NewNode) then 211 Result := StrToInt(string(NewNode.TextContent)); 190 212 end; 191 213 … … 195 217 begin 196 218 Result := DefaultValue; 197 NewNode := Node.FindNode( Name);198 if Assigned(NewNode) then 199 Result := StrToInt64( NewNode.TextContent);219 NewNode := Node.FindNode(DOMString(Name)); 220 if Assigned(NewNode) then 221 Result := StrToInt64(string(NewNode.TextContent)); 200 222 end; 201 223 … … 205 227 begin 206 228 Result := DefaultValue; 207 NewNode := Node.FindNode( Name);208 if Assigned(NewNode) then 209 Result := StrToBool( NewNode.TextContent);229 NewNode := Node.FindNode(DOMString(Name)); 230 if Assigned(NewNode) then 231 Result := StrToBool(string(NewNode.TextContent)); 210 232 end; 211 233 … … 215 237 begin 216 238 Result := DefaultValue; 217 NewNode := Node.FindNode( Name);218 if Assigned(NewNode) then 219 Result := NewNode.TextContent;239 NewNode := Node.FindNode(DOMString(Name)); 240 if Assigned(NewNode) then 241 Result := string(NewNode.TextContent); 220 242 end; 221 243 … … 226 248 begin 227 249 Result := DefaultValue; 228 NewNode := Node.FindNode( Name);229 if Assigned(NewNode) then 230 Result := XMLTimeToDateTime( NewNode.TextContent);250 NewNode := Node.FindNode(DOMString(Name)); 251 if Assigned(NewNode) then 252 Result := XMLTimeToDateTime(string(NewNode.TextContent)); 231 253 end; 232 254
Note:
See TracChangeset
for help on using the changeset viewer.