Ignore:
Timestamp:
Sep 10, 2022, 6:54:43 PM (20 months ago)
Author:
chronos
Message:
  • Modified: CoolTranslator replaced by Common package.
  • Modified: Update common package.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/UXMLUtils.pas

    r15 r25  
    11unit UXMLUtils;
    2 
    3 {$mode delphi}
    42
    53interface
     
    75uses
    86  {$IFDEF WINDOWS}Windows,{$ENDIF}
    9   Classes, SysUtils, DateUtils, XMLRead, XMLWrite, DOM;
     7  Classes, SysUtils, DateUtils, DOM, xmlread;
    108
    119function XMLTimeToDateTime(XMLDateTime: string): TDateTime;
    12 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString;
     10function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string;
    1311procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer);
    1412procedure WriteInt64(Node: TDOMNode; Name: string; Value: Int64);
     
    2119function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string;
    2220function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime): TDateTime;
     21procedure ReadXMLFileParser(out Doc: TXMLDocument; FileName: string);
    2322
    2423
    2524implementation
     25
     26procedure ReadXMLFileParser(out Doc: TXMLDocument; FileName: string);
     27var
     28  Parser: TDOMParser;
     29  Src: TXMLInputSource;
     30  InFile: TFileStream;
     31begin
     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;
     43end;
    2644
    2745function GetTimeZoneBias: Integer;
     
    3048  TimeZoneInfo: TTimeZoneInformation;
    3149begin
     50  {$push}{$warn 5057 off}
    3251  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;
    3554  else
    3655    Result := 0;
    3756  end;
     57  {$pop}
    3858end;
    3959{$ELSE}
     
    4565function LeftCutString(var Source: string; out Output: string; Delimiter: string; Allowed: string = ''): Boolean;
    4666var
    47   I, J: Integer;
     67  I: Integer;
    4868  Matched: Boolean;
    4969begin
     
    99119      if Pos('Z', XMLDateTime) > 0 then
    100120        LeftCutString(XMLDateTime, Part, 'Z');
    101       SecondFraction := StrToFloat('0' + DecimalSeparator + Part);
     121      SecondFraction := StrToFloat('0' + DefaultFormatSettings.DecimalSeparator + Part);
    102122      Millisecond := Trunc(SecondFraction * 1000);
    103123    end else begin
     
    118138end;
    119139
    120 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString;
     140function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string;
    121141const
    122142  Neg: array[Boolean] of string =  ('+', '-');
     
    139159  NewNode: TDOMNode;
    140160begin
    141   NewNode := Node.OwnerDocument.CreateElement(Name);
    142   NewNode.TextContent := IntToStr(Value);
     161  NewNode := Node.OwnerDocument.CreateElement(DOMString(Name));
     162  NewNode.TextContent := DOMString(IntToStr(Value));
    143163  Node.AppendChild(NewNode);
    144164end;
     
    148168  NewNode: TDOMNode;
    149169begin
    150   NewNode := Node.OwnerDocument.CreateElement(Name);
    151   NewNode.TextContent := IntToStr(Value);
     170  NewNode := Node.OwnerDocument.CreateElement(DOMString(Name));
     171  NewNode.TextContent := DOMString(IntToStr(Value));
    152172  Node.AppendChild(NewNode);
    153173end;
     
    157177  NewNode: TDOMNode;
    158178begin
    159   NewNode := Node.OwnerDocument.CreateElement(Name);
    160   NewNode.TextContent := BoolToStr(Value);
     179  NewNode := Node.OwnerDocument.CreateElement(DOMString(Name));
     180  NewNode.TextContent := DOMString(BoolToStr(Value));
    161181  Node.AppendChild(NewNode);
    162182end;
     
    166186  NewNode: TDOMNode;
    167187begin
    168   NewNode := Node.OwnerDocument.CreateElement(Name);
    169   NewNode.TextContent := Value;
     188  NewNode := Node.OwnerDocument.CreateElement(DOMString(Name));
     189  NewNode.TextContent := DOMString(Value);
    170190  Node.AppendChild(NewNode);
    171191end;
     
    175195  NewNode: TDOMNode;
    176196begin
    177   NewNode := Node.OwnerDocument.CreateElement(Name);
    178   NewNode.TextContent := DateTimeToXMLTime(Value);
     197  NewNode := Node.OwnerDocument.CreateElement(DOMString(Name));
     198  NewNode.TextContent := DOMString(DateTimeToXMLTime(Value));
    179199  Node.AppendChild(NewNode);
    180200end;
     
    185205begin
    186206  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));
    190210end;
    191211
     
    195215begin
    196216  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));
    200220end;
    201221
     
    205225begin
    206226  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));
    210230end;
    211231
     
    215235begin
    216236  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);
    220240end;
    221241
     
    226246begin
    227247  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));
    231251end;
    232252
Note: See TracChangeset for help on using the changeset viewer.