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.
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
NULLin arguments or returns
- No type casting or reflection
- No procedures or functions, only Interfaces and Objects
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
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')
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
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')
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')
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:
- Fork this project (Click on Fork button)
- Clone your forked project to your local machine
- Create a new issue describing about the problem or enhancement that you are going to make
- Create a new branch related to this issue. We suggest to use a name like
issue-10— 10 is the issue's ID
- Make all the changes necessary and commit
- Push the new branch to your Github repository
- Go to Xavier Github project and click on Compare & Pull Request
- 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.
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.