https://github.com/viniciussanchez/xml-reader
XML Reader for Delphi and Lazarus
https://github.com/viniciussanchez/xml-reader
delphi fpc lazarus reader xml
Last synced: 8 months ago
JSON representation
XML Reader for Delphi and Lazarus
- Host: GitHub
- URL: https://github.com/viniciussanchez/xml-reader
- Owner: viniciussanchez
- License: mit
- Created: 2022-05-31T19:42:18.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-02T13:32:57.000Z (over 1 year ago)
- Last Synced: 2025-02-11T12:53:40.202Z (10 months ago)
- Topics: delphi, fpc, lazarus, reader, xml
- Language: Pascal
- Homepage:
- Size: 30.3 KB
- Stars: 29
- Watchers: 6
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# XML Reader
## ⚙️ Installation
Installation is done using the [`boss install`](https://github.com/HashLoad/boss) command line:
``` sh
boss install viniciussanchez/xml-reader
```
## ⚙️ 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-reader/src
```
## ⚡️ Quickstart
```pascal
uses Xml.Reader;
```
#### Load from file
```pascal
var
LXmlReader: IXmlReader;
begin
LXmlReader := TXmlReader.New.LoadFromFile('C:\xml\nfe.xml');
end;
```
#### Load from string
```pascal
var
LXmlReader: IXmlReader;
begin
LXmlReader := TXmlReader.New.LoadFromString('my xml here!');
end;
```
#### Get xml version
```pascal
begin
Result := LXmlReader.Version;
end;
```
#### Get xml encoding
```pascal
begin
Result := LXmlReader.Encoding;
end;
```
#### Get main node
```pascal
var
LMainNode: IXmlNode;
begin
LMainNode := LXmlReader.Node;
end;
```
#### How to list nodes
```pascal
var
LNode: IXmlNode;
begin
for LNode in LMainNode.Nodes do
// my code here!
end;
```
#### How to list attributes
```pascal
var
LAttribute: IXmlAttribute;
begin
for LAttribute in LMainNode.Attributes do
// my code here!
end;
```
#### How to list elements
```pascal
var
LElement: IXmlElement;
begin
for LElement in LMainNode.Elements do
// my code here!
end;
```
#### Other resources
```pascal
var
LNode: IXmlNode;
LElement: IXmlElement;
LAttribute: IXmlAttribute;
begin
// get the name of a node
LNode.Name;
// check if the node has an attribute
LNode.ContainsAttribute('attribute name');
// check if the node has a node
LNode.ContainsNode('node name');
// check if the node has an element
LNode.ContainsElement('element name');
// get the value of an attribute from a node
LNode.GetAttribute('attribute name');
// get a node from a node
LNode.GetNode('node name');
// get the element of a node
LNode.GetElement('element name');
// get the attributes of a node
LNode.Attributes;
// get the elements of a node
LNode.Elements;
// get the nodes of a node
LNode.Nodes;
// get the name of an element
LElement.Name;
// get the value of an element
LElement.Value;
// get the value in string format from an element
LElement.AsString;
// get the value in integer format of an element
LElement.AsInteger;
// get the name of an attribute
LAttribute.Name;
// get the value of an attribute
LAttribute.Value;
// get the value in string format of an attribute
LAttribute.AsString;
// get the value in integer format of an attribute
LAttribute.AsInteger;
end;
```
## ⚠️ License
`XML Reader` is free and open-source software licensed under the [MIT License](https://github.com/viniciussanchez/xml-reader/blob/master/LICENSE).