Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Create and parse XML documents using Winsoft’s library XML

  1. Introduction

XML is a VCL-type library (Windows platform only). Its main purpose is to create and parse XML documents. If you need installation instructions watch the video below.

2. Components in the Demo and what they do

Memo.Lines.Clear;
  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;
      Memo.Lines.Add(Text);
    end
  finally
    Free;
  end;
function NodeToString(Node: TXmlNode): string;
  begin
    case Node of
      xnNone: Result := 'None';
      xnElement: Result := 'Element';
      xnAttribute: Result := 'Attribute';
      xnText: Result := 'Text';
      xnCData: Result := 'CData';
      xnProcessingInstruction: Result := 'Processing instruction';
      xnComment: Result := 'Comment';
      xnDocumentType: Result := 'Document type';
      xnWhitespace: Result := 'White space';
      xnEndElement: Result := 'End element';
      xnXmlDeclaration: Result := 'Declaration';
      else Result := '';
    end;
  end;
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;
  ShowMessage('document.xml created');

A short video shows the library in action.

You can download the Demo here.

Like what you see? You can get the XML Library and over 100 other fantastic WinSoft components with our Enterprise Component Pack. For a limited time, when you purchase RAD Studio Enterprise or Architect Edition at special Upgrade Pricing, you will also get this package of third-party software worth over $13,000, including the full WinSoft Component Library, at NO EXTRA COST! Step up to RAD Studio 10.4.1 today!

Exit mobile version