Winsoft XML Library 1.1 » Developer.Team - Developers Paradise!
star archive bad ca calendar cat coms dislike down down2 fav fb gp info left like login love mail od pass rel reply right search set share sort_down sort_up top tw up views vk votes cross phone loc ya

Winsoft XML Library 1.1

Winsoft XML Library 1.1
Winsoft XML Library 1.1


uses standard Windows XmlLite API
supports Windows 32 and Windows 64
available for Delphi/C++ Builder 7 - 10.2 and Lazarus 1.8.2
source code included in registered version
royalty free distribution in applications

API
const
  XmlFileExtension = '.xml';
  XmlMIME = 'application/xml';

type
  TXmlNode =
  (
    xnNone,
    xnElement,
    xnAttribute,
    xnText,
    xnCData,
    xnProcessingInstruction,
    xnComment,
    xnDocumentType,
    xnWhitespace,
    xnEndElement,
    xnXmlDeclaration
  );

  TXmlReader = class
  public
    constructor Create(Stream: IStream; const Encoding: string = '');
    constructor Create(Stream: TStream; const Encoding: string = '');
    constructor Create(const FileName: string; const Encoding: string = '');

    procedure Attribute(const Name: string; const Namespace: string = '');
    procedure Element;
    procedure FirstAttribute;
    procedure NextAttribute;
    function Read: Boolean;

    property AttributeCount: Integer read;
    property Depth: Integer read;
    property EmptyElement: Boolean read;
    property Eof: Boolean read;
    property Line: Integer read;
    property Name: string read;
    property Namespace: string read;
    property Node: TXmlNode read;
    property Position: Integer read;
    property Prefix: string read;
    property QualifiedName: string read;
    property Reader: IXmlReader read;
    property Value: string read;
  end;

  TXmlWriter = class
  public
    constructor Create(Stream: IStream; const Encoding: string = '');
    constructor Create(Stream: TStream; const Encoding: string = '');
    constructor Create(const FileName: string; const Encoding: string = '');

    procedure StartDocument;
    procedure EndDocument;

    procedure StartElement(const Name: string; const Prefix: string = ''; const Namespace: string = '');
    procedure EndElement;

    procedure Attribute(const Name: string; const Value: string; const Prefix: string = ''; const Namespace: string = '');
    procedure CData(const Data: string);
    procedure Comment(const Text: string);
    procedure Raw(const Data: string);
    procedure Text(const Text: string);

    procedure Flush;

    property Indent: Boolean read write;
    property Writer: IXmlWriter read;
    property XmlDeclaration: Boolean read write;
  end;
Examples
// create XML document
with TXmlWriter.Create('document.xml') do
try
  Indent := True;
  StartDocument;
    StartElement('element1');

      Comment('comment');

      StartElement('element2');
        Attribute('attribute1', 'value1');
        Attribute('attribute2', 'value2');
        Text('Hello, world!');
      EndElement;

      StartElement('element3');
        CData('data');
      EndElement;

    EndElement;
  EndDocument;
finally
  Free;
end;

// parse XML document
var
  Text: string;
  I: Integer;

with TXmlReader.Create('document.xml') do
try
  while Read do
  begin
    Text := IntToStr(Line) + ',' + IntToStr(Position) + ': ' + NodeToString(Node);
    case Node of
      xnElement:
      begin
        Text := Text + ': ' + Name;
        Element;
        FirstAttribute;
        for I := 1 to AttributeCount do
        begin
          Text := Text + ' ' + Name + '=' + Value;
          NextAttribute;
        end;
      end;

      xnText: Text := Text + ': ' + Value;
      xnCData: Text := Text + ': ' + Value;
      xnComment: Text := Text + ': ' + Value;
      xnWhitespace: Text := Text + ': "' + Value + '"';
      xnEndElement: Text := Text + ': ' + Name;
      xnXmlDeclaration: Text := Text + ': ' + Name;
    end;
    ShowMessage(Text);
  end
finally
  Free;
end;


Only for V.I.P
Warning! You are not allowed to view this text.