Xavier is an object-oriented library for working with XML.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
inc
pkg
src
test #19: uses section was changed Nov 5, 2017
.gitignore
LICENSE
README.md
XavierGroup.groupproj

README.md

Xavier

License

Xavier is an object-oriented library for working with XML.

ATTENTION: We're still in a very early alpha version, the API may and will change frequently. Please, use it at your own risk, until we release version 1.0.

This API is being written in Free Pascal and Lazarus. However, it is compatible with Delphi too.

Why. Nowadays, all XML libraries are very complex. Each class has so many methods that could be hard to use and understand them. These implementations are very procedural too.

The major goal of this project is to replace common procedural code in our projects, which could have so many conditionals and variables, to a declarative and object-oriented code to work more easily with XML.

We want to write elegant, clean, and maintainable code using OOP.

Principles. The code has some design principles:

  • Fully interface-based
  • Memory is released automatically
  • No usage of nil/NULL in arguments or returns
  • No type casting or reflection
  • No procedures or functions, only Interfaces and Objects

Quick Start

Find a Node

Take this XML for example:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <foo a1="f1" a2="f2">
    <value>foo</value>
  </foo>
  <bar a1="b1" a2="b2">
    <value>bar</value>
  </bar>
</root>

If you want to find the value child node of foo node, do this:

var
  N: IXMLNode;
begin
  N := TXMLPack.New(
    TFile.New('file.xml').Stream
  ).Node('/root/foo/value');
  ShowMessage(N.Text); // "foo"
end.

In fact, we don't need this variable N. Just call Text directly.

Add Node

You can add a node easily doing this:

// add a new node: name="item" value="a"
TXMLPack.New(TFile.New('file.xml').Stream)
  .Node('/root')
  .Add('item')
  .Value('a')

Childs Count

You can count how many childs a node have doing this:

// How many childs
TXMLPack.New(TFile.New('file.xml').Stream)
  .Node('/root')
  .Childs
  .Count

Find Attribute

You can find any attribute by name doing this:

// Find by name "id"
TXMLPack.New(TFile.New('file.xml').Stream)
  .Node('/root')
  .Attrs
  .Item('id')

Add Attribute

Adding an attribute is quite easy too:

// Add an attribute: name="foo" value="bar"
TXMLPack.New(TFile.New('file.xml').Stream)
  .Node('/root')
  .Attrs
  .Add('foo', 'bar')

Dependencies

Internally, this project uses other built-in XML library for each compiler. Besides that, we are using other packages:

  • James — is a collection of classes and interfaces for truly object-oriented projects.

How to contribute?

To contribute we suggest following these steps:

  1. Fork this project (Click on Fork button)
  2. Clone your forked project to your local machine
  3. Create a new issue describing about the problem or enhancement that you are going to make
  4. Create a new branch related to this issue. We suggest to use a name like issue-10 — 10 is the issue's ID
  5. Make all the changes necessary and commit
  6. Push the new branch to your Github repository
  7. Go to Xavier Github project and click on Compare & Pull Request

Important:

  • It is important for you create a new branch for each PR. We might need to request some further changes in your work, and having the original PR's code to make these changes is better than working with the whole code.
  • Each PR needs to work only in one issue, respecting the single responsibility principle.
  • Make sure your branch builds without any warnings/issues.

If you have questions or general suggestions, don't hesitate to submit a new Github issue.

Contributors

License (MIT)

Copyright (c) 2017 Marcos Douglas B. Santos

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.