How to resolve the algorithm XML/Output step by step in the Ada programming language
How to resolve the algorithm XML/Output step by step in the Ada programming language
Table of Contents
Problem Statement
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of
Let's start with the solution:
Step by Step solution about How to resolve the algorithm XML/Output step by step in the Ada programming language
Source code in the ada programming language
with Ada.Strings.Unbounded;
with Ada.Text_IO.Text_Streams;
with DOM.Core.Documents;
with DOM.Core.Elements;
with DOM.Core.Nodes;
procedure Character_Remarks is
package DC renames DOM.Core;
package IO renames Ada.Text_IO;
package US renames Ada.Strings.Unbounded;
type Remarks is record
Name : US.Unbounded_String;
Text : US.Unbounded_String;
end record;
type Remark_List is array (Positive range <>) of Remarks;
My_Remarks : Remark_List :=
((US.To_Unbounded_String ("April"),
US.To_Unbounded_String ("Bubbly: I'm > Tam and <= Emily")),
(US.To_Unbounded_String ("Tam O'Shanter"),
US.To_Unbounded_String ("Burns: ""When chapman billies leave the street ...""")),
(US.To_Unbounded_String ("Emily"),
US.To_Unbounded_String ("Short & shrift")));
My_Implementation : DC.DOM_Implementation;
My_Document : DC.Document := DC.Create_Document (My_Implementation);
My_Root_Node : DC.Element := DC.Nodes.Append_Child (My_Document,
DC.Documents.Create_Element (My_Document, "CharacterRemarks"));
My_Element_Node : DC.Element;
My_Text_Node : DC.Text;
begin
for I in My_Remarks'Range loop
My_Element_Node := DC.Nodes.Append_Child (My_Root_Node,
DC.Documents.Create_Element (My_Document, "Character"));
DC.Elements.Set_Attribute (My_Element_Node, "Name", US.To_String (My_Remarks (I).Name));
My_Text_Node := DC.Nodes.Append_Child (My_Element_Node,
DC.Documents.Create_Text_Node (My_Document, US.To_String (My_Remarks (I).Text)));
end loop;
DC.Nodes.Write (IO.Text_Streams.Stream (IO.Standard_Output),
N => My_Document,
Pretty_Print => True);
end Character_Remarks;
with Ada.Wide_Wide_Text_IO;
with League.Strings;
with XML.SAX.Attributes;
with XML.SAX.Pretty_Writers;
procedure Main is
function "+"
(Item : Wide_Wide_String) return League.Strings.Universal_String
renames League.Strings.To_Universal_String;
type Remarks is record
Name : League.Strings.Universal_String;
Remark : League.Strings.Universal_String;
end record;
type Remarks_Array is array (Positive range <>) of Remarks;
------------
-- Output --
------------
procedure Output (Remarks : Remarks_Array) is
Writer : XML.SAX.Pretty_Writers.SAX_Pretty_Writer;
Attributes : XML.SAX.Attributes.SAX_Attributes;
begin
Writer.Set_Offset (2);
Writer.Start_Document;
Writer.Start_Element (Qualified_Name => +"CharacterRemarks");
for J in Remarks'Range loop
Attributes.Clear;
Attributes.Set_Value (+"name", Remarks (J).Name);
Writer.Start_Element
(Qualified_Name => +"Character", Attributes => Attributes);
Writer.Characters (Remarks (J).Remark);
Writer.End_Element (Qualified_Name => +"Character");
end loop;
Writer.End_Element (Qualified_Name => +"CharacterRemarks");
Writer.End_Document;
Ada.Wide_Wide_Text_IO.Put_Line (Writer.Text.To_Wide_Wide_String);
end Output;
begin
Output
(((+"April", +"Bubbly: I'm > Tam and <= Emily"),
(+"Tam O'Shanter", +"Burns: ""When chapman billies leave the street ..."""),
(+"Emily", +"Short & shrift")));
end Main;
You may also check:How to resolve the algorithm Documentation step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Empty string step by step in the TUSCRIPT programming language
You may also check:How to resolve the algorithm Jaro similarity step by step in the CoffeeScript programming language
You may also check:How to resolve the algorithm System time step by step in the Lasso programming language
You may also check:How to resolve the algorithm Comments step by step in the JCL programming language