Glib.XML

Entities

Generic formal parameters

Record Types

Access Types

Subprograms

Generic Instantiations

Description

This package provides a simple minded XML parser to be used with Gate.

<group>Glib, the general-purpose library</group>

Add_Child

procedure Add_Child
  (N : Node_Ptr; Child : Node_Ptr; Append : Boolean := False)

Add a new child to a node. If Append is true, the child is added at the end of the current list of children.

Parameters
N
Child
Append

Children_Count

function Children_Count (N : Node_Ptr) return Natural

Return the number of child nodes

Parameters
N
Return Value

Deep_Copy

function Deep_Copy (N : Node_Ptr) return Node_Ptr

Return a deep copy of the tree starting with N. N can then be freed without affecting the copy.

Parameters
N
Return Value

Find_Tag

function Find_Tag (N : Node_Ptr; Tag : UTF8_String) return Node_Ptr

Find a tag Tag in N and its brothers.

Parameters
N
Tag
Return Value

Find_Tag_With_Attribute

function Find_Tag_With_Attribute
  (N     : Node_Ptr;
   Tag   : UTF8_String;
   Key   : UTF8_String;
   Value : UTF8_String := "")
  return Node_Ptr

Find a tag Tag in N that has a given key (and value if given).

Parameters
N
Tag
Key
Value
Return Value

Free

procedure Free is new Ada.Unchecked_Deallocation (String, String_Ptr);

</doc_ignore>

Free

procedure Free
  (N : in out Node_Ptr; Free_Data : Free_Specific_Data := null)

Free the memory allocated for a node and its children. It also disconnects N from its parent. If Free_Data is not null, it is used to free the memory occupied by the Specific_Data for each node.

Parameters
N
Free_Data

Free_Specific_Data

type Free_Specific_Data is access
  procedure (Data : in out XML_Specific_Data);
Parameters
Data

Get_Attribute

function Get_Attribute
  (N              : Node_Ptr;
   Attribute_Name : UTF8_String;
   Default        : UTF8_String := "") return UTF8_String

Return the value of the attribute 'Attribute_Name' if present. Special XML characters have already been interpreted in the result string. Return Default otherwise.

Parameters
N
Attribute_Name
Default
Return Value

Get_Field

function Get_Field (N : Node_Ptr; Field : UTF8_String) return String_Ptr

Return the value of the field 'Field' if present in the children of N. Return null otherwise. Do not free the returned value.

Parameters
N
Field
Return Value

Is_Equal

function Is_Equal (Node1, Node2 : Node_Ptr) return Boolean

Compare two XML nodes recursively, and returns True if they are equal. Casing in attributes is relevant. Order of attributes is also relevant.

Parameters
Node1
Node2
Return Value

Node

type Node is record
   Tag   : String_Ptr;
   Attributes   : String_Ptr;
   Value : String_Ptr;
   Parent : Node_Ptr;
   Child : Node_Ptr;
   Next  : Node_Ptr;
   Specific_Data : XML_Specific_Data;
end record;

A node of the XML tree. Each time a tag is found in the XML file, a new node is created, that points to its parent, its children and its siblings (nodes at the same level in the tree and with the same parent).

Record fields
Tag

The name of this node. This is utf8-encoded

Attributes

The attributes of this node. This is utf8-encoded

Value

The value, or null is not relevant. This is utf8-encoded

Parent

The parent of this Node.

Child

The first Child of this Node. The next child is Child.Next

Next

Next sibling node.

Specific_Data

Use to store data specific to each implementation (e.g a boolean indicating whether this node has been accessed)

Node_Ptr

type Node_Ptr is access all Node;

Pointer to a node of the XML tree.

Parse

function Parse (File : String) return Node_Ptr

Parse File and return the first node representing the XML file.

Parameters
File
Return Value

Parse_Buffer

function Parse_Buffer (Buffer : UTF8_String) return Node_Ptr

Parse a given Buffer in memory and return the first node representing the XML contents.

Parameters
Buffer
Return Value

Print

procedure Print (N : Node_Ptr; File_Name : String := "")

Write the tree starting with N into a file File_Name. The generated file is valid XML, and can be parsed with the Parse function. If File_Name is the empty string, then the tree is printed on the standard output

Parameters
N
File_Name

Print

procedure Print
  (N         : Node_Ptr;
   File_Name : String;
   Success   : out Boolean)

Same as above, with Success reporting the success of the operation.

Parameters
N
File_Name
Success

Protect

function Protect (S : String) return String

Return a copy of S modified so that it is a valid XML value

Parameters
S
Return Value

Set_Attribute

procedure Set_Attribute
  (N : Node_Ptr; Attribute_Name, Attribute_Value : UTF8_String)

Create a new attribute, or replace an existing one. The attribute value is automatically protected for special XML characters

Parameters
N
Attribute_Name
Attribute_Value

XML_Specific_Data

type XML_Specific_Data is private;

The type of the extra data that can be attached to each node of the XML tree. See for instance the package Glib.Glade.