Ignore:
Timestamp:
Sep 8, 2010, 4:17:21 PM (14 years ago)
Author:
george
Message:
  • Přidáno: Z PHP kódů převedeno zobrazení stránek a hlavního menu. Pro generování kostry použity třídy HTMLClasses a XMLClasses.
  • Přidáno: Styly a obrázky.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/lazarus/Common/UXmlClasses.pas

    r23 r24  
    55interface
    66
    7 uses Classes, SysUtils, Contnrs, StrUtils;
     7uses Classes, SysUtils, Contnrs, StrUtils, UStringListEx;
    88
    99type
    10   TStringListEx = class(TStringList)
    11   public
    12     procedure AddNameValue(Name, Value: string);
    13   end;
    14 
    1510  TXmlElement = class
    1611  private
     
    3126    function GetAsString: string; override;
    3227  public
    33     EndTagSymbol: Char;
    34     TagName: string;
     28    EndTagSymbol: string;
     29    ShringEmpty: Boolean;
     30    Name: string;
    3531    Attributes: TStringListEx;
    36     SubElements: TList; // of TXmlElement;
     32    SubElements: TObjectList; // of TXmlElement;
    3733    constructor Create;
    3834    destructor Destroy; override;
     
    4137  TXmlDocument = class
    4238  private
     39    MainTag: TXmlTag;
    4340    function FormatStructure(Text: string): string;
    4441    function GetAsString: string;
    4542  public
    4643    Formated: Boolean;
    47     MainTag: TXmlTag;
    4844    Content: TXmlTag;
    4945    XmlVersion: string;
     
    6056constructor TXmlTag.Create;
    6157begin
     58  ShringEmpty := True;
    6259  Attributes := TStringListEx.Create;
    6360  Attributes.NameValueSeparator := '=';
    64   SubElements := TList.Create;
     61  SubElements := TObjectList.Create;
    6562  EndTagSymbol := '/';
    6663end;
    6764
    6865destructor TXmlTag.Destroy;
    69 var
    70   I: Integer;
    7166begin
    7267  Attributes.Free;
    73   for I := 0 to SubElements.Count - 1 do TXmlElement(SubElements[I]).Free;
    7468  SubElements.Free;
    7569  inherited;
     
    9084    AttributesText := AttributesText + ' ' + Attributes.Names[I] + '="' + Attributes.ValueFromIndex[I] + '"';
    9185
    92   if TagName <> '' then begin
    93     if Content <> '' then
    94       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 + '>';
    9690  end else Result := Content;
    9791end;
     
    116110begin
    117111  inherited;
    118   Encoding := 'windows-1250';
     112  Encoding := 'utf-8';
    119113  XmlVersion := '1.0';
    120114  MainTag := TXmlTag.Create;
    121115  with MainTag do begin
    122     TagName := '?xml';
     116    Name := '?xml';
    123117    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');
    126120  end;
    127121  Content := TXmlTag.Create;
     
    172166function TXmlDocument.GetAsString: string;
    173167begin
    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;
    177169  if Formated then Result := FormatStructure(Result);
    178170end;
    179171
    180 { TStringListEx }
    181 
    182 procedure TStringListEx.AddNameValue(Name, Value: string);
    183 begin
    184   Add(Name + NameValueSeparator + Value);
    185 end;
    186 
    187172end.
Note: See TracChangeset for help on using the changeset viewer.