Code Monkey home page Code Monkey logo

xml-builder's Introduction

XML Builder

⚙️ Installation

Installation is done using the boss install command line:

boss install viniciussanchez/xml-builder

⚙️ Manual Installation for Delphi

If you choose to install manually, simply add the following folders to your project, in Project > Options > Resource Compiler > Directories and Conditionals > Include file search path

../xml-builder/src

⚡️ Quickstart

uses Xml.Builder;

var
  LDeveloperNode, LProjectsNode: IXmlNode;
begin
  LProjectsNode := TXmlNode.New('projects')
    .AddElement('Horse', 'yes')
    .AddElement('Boss', 'yes')
    .AddElement('RESTRequest4Delphi', 'yes')
    .AddElement('DataSet-Serialize', 'yes')
    .AddElement('BCrypt', 'yes');

  LDeveloperNode := TXmlNode.New('developer')
    .AddAttribute('mvp', 'true')
    .AddElement('firstName', 'Vinicius')
    .AddElement('lastName', 'Sanchez')
    .AddElement('age')
    .AddNode(LProjectsNode);

  TXmlBuilder.New
    .AddNode(LDeveloperNode)
    .Xml;
end;

// Another way to implement:

begin
  TXmlBuilder.New
    .AddNode(TXmlNode.New('developer')
      .AddAttribute('mvp', 'true')
      .AddElement('firstName', 'Vinicius')
      .AddElement('lastName', 'Sanchez')
      .AddElement('age')
      .AddNode(TXmlNode.New('projects')
        .AddElement('Horse', 'yes')
        .AddElement('Boss', 'yes')
        .AddElement('RESTRequest4Delphi', 'yes')
        .AddElement('DataSet-Serialize', 'yes')
        .AddElement('BCrypt', 'yes')))
    .Xml;
end;

Result:

<?xml version="1.0" encoding="UTF-8"?>
<developer mvp="true">
   <firstName>Vinicius</firstName>
   <lastName>Sanchez</lastName>
   <age />
   <projects>
      <Boss>yes</Boss>
      <DataSet-Serialize>yes</DataSet-Serialize>
      <RESTRequest4Delphi>yes</RESTRequest4Delphi>
      <BCrypt>yes</BCrypt>
      <Horse>yes</Horse>
   </projects>
</developer>

You can also save the file to disk:

TXmlBuilder.New.SaveToFile('C:\sample.xml');

⚡️ DataSet Adapter

uses Xml.Builder;

begin
  mtDeveloper.Append;
  mtDeveloperfirstName.AsString := 'Vinicius';
  mtDeveloperlastName.AsString := 'Sanchez';
  mtDevelopermvp.AsBoolean := True;
  mtDeveloper.Post;
  
  mmXml.Lines.Text := TXmlBuilder.Adapter(mtDeveloper).Xml;
end;

Result:

<?xml version="1.0" encoding="UTF-8"?>
<mtDeveloper>
   <firstName>Vinicius</firstName>
   <lastName>Sanchez</lastName>
   <mvp>True</mvp>
</mtDeveloper>

⚠️ License

XML Builder is free and open-source software licensed under the MIT License.

xml-builder's People

Contributors

viniciussanchez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.