------------------------------------------------------------------------------ -- XML/Ada - An XML suite for Ada95 -- -- -- -- Copyright (C) 2001-2012, AdaCore -- -- -- -- This library is free software; you can redistribute it and/or modify it -- -- under terms of the GNU General Public License as published by the Free -- -- Software Foundation; either version 3, or (at your option) any later -- -- version. This library is distributed in the hope that it will be useful, -- -- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- -- -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- -- -- -- -- -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- . -- -- -- ------------------------------------------------------------------------------ -- In addition to the SAX standard, we have added an extra field to -- Attributes to memorize the default declaration for the attribute -- (REQUIRED, IMPLIED, FIXED). -- Likewise, enumerations are represented in a full structure, rather than -- a simple string. -- We have also merged the interfaces Attributes and Attributes_Impl, for -- ease of use. with Unicode.CES; with Sax.Models; package Sax.Attributes is type attributes is tagged private; No_Attributes : constant attributes; type default_declaration is (required, implied, fixed, default); -- See 3.3.2 in XML specifications type attribute_type is (cdata, id, idref, idrefs, entity, entities, nmtoken, nmtokens, notation, enumeration); -- See 3.3.1 in XML specifications. The last value "Enumeration" -- corresponds to a model like "(a|b)*",... -------------------------- -- Attributes interface -- -------------------------- -- In the following functions, an empty string is returned when the -- index is out of bounds. -- Indexes are zero-based. function Get_Index (Attr : attributes; URI : Unicode.CES.byte_sequence; Local_Name : Unicode.CES.byte_sequence) return Integer; function Get_Index (Attr : attributes; Local_Name : Unicode.CES.byte_sequence) -- no namespace return Integer; -- Look up the index of an attribute by Namespace name -- (-1) is returned if there is no match function Get_Length (Attr : attributes) return Natural; -- Return the number of attributes in the list function Get_Local_Name (Attr : attributes; Index : Natural) return Unicode.CES.byte_sequence; -- Return an attribute's local name by index function Get_Prefix (Attr : attributes; Index : Natural) return Unicode.CES.byte_sequence; -- Return the prefix used for the attribute in the XML file function Get_Qname (Attr : attributes; Index : Natural) return Unicode.CES.byte_sequence; -- Return an attribute's qualified name by index function Get_Type (Attr : attributes; Index : Natural) return attribute_type; -- Return an attribute's type by index function Get_Type (Attr : attributes; Qname : Unicode.CES.byte_sequence) return attribute_type; -- Return an attribute's type by XML 1.0 qualified name function Get_Type (Attr : attributes; URI : Unicode.CES.byte_sequence; Local_Name : Unicode.CES.byte_sequence) return attribute_type; -- Return an attribute's type by Namespace name, or "CDATA" if the type -- is unknown. function Get_URI (Attr : attributes; Index : Natural) return Unicode.CES.byte_sequence; -- Return an attribute's Namespace URI by index function Get_Value (Attr : attributes; Index : Natural) return Unicode.CES.byte_sequence; function Get_Value_As_Boolean (Attr : attributes; Index : Natural) return Boolean; -- Return an attribute's value by index. -- The second function will test the value's attribute against the standard -- set of boolean values ("true", "1", "false", "0") function Get_Value (Attr : attributes; Qname : Unicode.CES.byte_sequence) return Unicode.CES.byte_sequence; function Get_Value_As_Boolean (Attr : attributes; Qname : Unicode.CES.byte_sequence) return Boolean; -- Return an attribute's value by XML 1.0 qualified name function Get_Value (Attr : attributes; URI : Unicode.CES.byte_sequence; Local_Name : Unicode.CES.byte_sequence) return Unicode.CES.byte_sequence; function Get_Value_As_Boolean (Attr : attributes; URI : Unicode.CES.byte_sequence; Local_Name : Unicode.CES.byte_sequence) return Boolean; -- Return an attribute's value by Namespace name function Get_Content (Attr : attributes; Index : Natural) return Sax.Models.content_model; -- Return the content model for the attribute. -- This function doesn't exist in the SAX 2.0 standard. -- If you need to keep a copy of the returned type, you must Ref it. procedure Set_Content (Attr : attributes; Index : Natural; Content : Sax.Models.content_model); -- Set the content model for the attribute. -- Content is automatically Refed internally, so that caller is still -- responsible for Unref-ing any reference it owns. function Get_Default_Declaration (Attr : attributes; Index : Natural) return default_declaration; -- Return the specification used for the default value of the attribute. -- This function is not part of the SAX 2.0 standard. procedure Add_Attribute (Attr : in out attributes; URI : Unicode.CES.byte_sequence; Local_Name : Unicode.CES.byte_sequence; Qname : Unicode.CES.byte_sequence; Att_Type : attribute_type; Content : Sax.Models.content_model; Value : Unicode.CES.byte_sequence; Default_Decl : default_declaration := default); -- Add an attribute to the end of the list. -- For the sake of speed, this function doesn't check if the attribute is -- already in the list, this is the responsability of the application. -- Content should be null unless Att_Type is Notation or Enumeration. -- -- The counting for Content is incremented, so you are still responsible -- for calling Unref after this procedure. procedure Clear (Attr : in out attributes); -- Clear the list of attributes for reuse (or to free the memory allocated -- for it). You should always call this procedure when you are done with -- the attribute list. procedure Remove_Attribute (Attr : in out attributes; Index : Natural); -- Remove an attribute from the list, by index. procedure Set_Attribute (Attr : in out attributes; Index : Natural; URI : Unicode.CES.byte_sequence; Local_Name : Unicode.CES.byte_sequence; Qname : Unicode.CES.byte_sequence; Att_Type : attribute_type; Content : Sax.Models.content_model; Value : Unicode.CES.byte_sequence; Default_Decl : default_declaration := default); -- Set an attribute in the list. -- For the sake of speed, this function doesn't check if the attribute is -- already in the list, this is the responsability of the application. -- Content is Refed internally, so the caller still needs to Unref it if it -- owns a reference to the model procedure Set_Attributes (Attr : in out attributes; From : attributes'class); -- Copy an entire attribute object procedure Set_Local_Name (Attr : in out attributes; Index : Natural; Local_Name : Unicode.CES.byte_sequence); -- Set the local name of a specific attribute in the list procedure Set_Qname (Attr : in out attributes; Index : Natural; Qname : Unicode.CES.byte_sequence); -- Set the XML 1.0 qualified name of a specific attribute in the list procedure Set_Type (Attr : in out attributes; Index : Natural; Att_Type : attribute_type); -- Set the type of a specific attribute in the list procedure Set_URI (Attr : in out attributes; Index : Natural; URI : Unicode.CES.byte_sequence); -- Set the Namespace URI of a specific attribute in the list procedure Set_Value (Attr : attributes; Index : Natural; Value : Unicode.CES.byte_sequence); -- Set the value of a specific attribute in the list function Get_Non_Normalized_Value (Attr : attributes; URI : Unicode.CES.byte_sequence; Local_Name : Unicode.CES.byte_sequence) return Unicode.CES.byte_sequence; -- Get the value of the attribute before normalization Out_Of_Bounds : exception; -- Raised when Index is out of bounds in all the Set_* subprograms. private type attribute; type attribute_access is access attribute; type attribute is record URI : Unicode.CES.byte_sequence_access; Local_Name : Unicode.CES.byte_sequence_access; Value : Unicode.CES.byte_sequence_access; Non_Normalized_Value : Unicode.CES.byte_sequence_access; Att_Type : attribute_type; Qname : Unicode.CES.byte_sequence_access; Default_Decl : default_declaration; Content : Sax.Models.content_model := Sax.Models.Unknown_Model; Next : attribute_access; end record; type attributes is tagged record Length : Natural := 0; First : attribute_access; Last : attribute_access; end record; No_Attributes : constant attributes := (0, null, null); end Sax.Attributes;