File: testxml.adb

package info (click to toggle)
libaws 2.2dfsg-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 7,624 kB
  • ctags: 1,173
  • sloc: ada: 61,829; ansic: 6,483; makefile: 1,282; xml: 196; sh: 119; java: 112; python: 66; sed: 40
file content (98 lines) | stat: -rw-r--r-- 2,456 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
--  TestXML program modified for get XML source from AWS HTTP client
--  connection.

with GNAT.Command_Line;  use GNAT.Command_Line;
with DOM.Readers;        use DOM.Readers;
with Sax.Readers;        use Sax.Readers;
with DOM.Core.Nodes;     use DOM.Core.Nodes;
with Ada.Exceptions;     use Ada.Exceptions;
with Ada.Text_IO;        use Ada.Text_IO;

with AWS.Client.XML.Input_Sources;
with AWS.Response;

procedure Testxml is
   use AWS.Client.XML.Input_Sources;

   Silent : Boolean := False;
   With_URI : Boolean := False;
   HTTP : AWS.Client.HTTP_Connection;
   Read : HTTP_Input;
   My_Tree_Reader : Tree_Reader;
   Name_Start : Natural;
   Validate : Boolean := False;
   Must_Normalize : Boolean := False;

   Dummy : AWS.Response.Data;

begin
   --  Parse the command line
   loop
      case Getopt ("silent uri normalize validate") is
         when ASCII.Nul => exit;

         when 's' => Silent := True;
         when 'u' => With_URI := True;
         when 'v' => Validate := True;
         when 'n' => Must_Normalize := True;

         when others => null;
      end case;
   end loop;

   declare
      S : constant String := Get_Argument;
   begin
      if S'Length > 0 then
         AWS.Client.Create
           (HTTP,
            Host        => S,
            Server_Push => True,
            Persistent  => False);

         AWS.Client.Get (HTTP, Dummy);

         --  Base file name should be used as the public Id
         Name_Start := S'Last;

         while Name_Start >= S'First  and then S (Name_Start) /= '/' loop
            Name_Start := Name_Start - 1;
         end loop;

         Set_Public_Id (Read, S (Name_Start + 1 .. S'Last));

         Create (HTTP, Read);

         --  Full name is used as the system id
         Set_System_Id (Read, S);

      else
         Put_Line ("define URL of XML file in command line.");
      end if;
   end;

   Set_Feature (My_Tree_Reader, Validation_Feature, Validate);

   Parse (My_Tree_Reader, Read);
   Close (Read);
   AWS.Client.Close (HTTP);

   if Must_Normalize then
      Normalize (Get_Tree (My_Tree_Reader));
   end if;

   if not Silent then
      Print (Get_Tree (My_Tree_Reader),
             Print_Comments => False,
             Print_XML_PI => False,
             With_URI => With_URI);
   end if;

   Free (My_Tree_Reader);

exception
   when E : XML_Fatal_Error =>
      Close (Read);
      Put_Line (Exception_Message (E));
      Free (My_Tree_Reader);
end Testxml;