home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / exml.lha / exml / examples / tree_test / root_class.e < prev   
Text File  |  1999-04-13  |  2KB  |  78 lines

  1. indexing
  2.     description:    "demonstration of using the tree based xml parser";
  3.     note:                 "this example compiles with ISE Eiffel and SmallEiffel.%
  4.                         %Therefore GOBO library must be correctly installed.";
  5.  
  6. class
  7.     ROOT_CLASS
  8. inherit
  9.     EXPAT_ERROR_CODES
  10.     KL_INPUT_STREAM_ROUTINES
  11. creation
  12.  
  13.     make
  14.  
  15. feature -- Initialization
  16.  
  17.     make is
  18.         do
  19.             !! parser.make
  20.  
  21.             -- TODO: Use enviroment variables instead !
  22.             -- ?Is there an easy way to do this?
  23.     
  24.                 -- uncomment the following line for ise
  25.             -- parse_file ("..\..\..\test_data\test.xml")
  26.                 -- uncomment the following line for se
  27.             parse_file ("..\test_data\test.xml")
  28.             
  29.         end;
  30.  
  31.     parser: XML_TREE_PARSER
  32.  
  33.     parse_file (file_name: STRING) is
  34.         require
  35.             file_name_not_void: file_name /= Void
  36.             
  37.         local
  38.             in_file: like INPUT_STREAM_TYPE
  39.             buffer: STRING
  40.         do
  41.             in_file := make_file_open_read (file_name)
  42.  
  43.             check
  44.                 file_open: is_open_read (in_file)
  45.             end
  46.  
  47.             from
  48.             until
  49.                 end_of_input (in_file) or not parser.is_correct
  50.             loop
  51.         
  52.                 buffer := read_string (in_file, 10)
  53.  
  54.                 --check
  55.                 --    file_state_consitency_check: (buffer.count = 0) = end_of_input (in_file)
  56.                 --end
  57.                 -- TODO: check doesn't work with se ??!?!
  58.  
  59.                 if
  60.                     buffer.count > 0
  61.                 then
  62.                     parser.parse_string (buffer)
  63.                 else
  64.                     parser.set_end_of_file    
  65.                 end
  66.  
  67.                 if
  68.                     not parser.is_correct
  69.                 then
  70.                     print (parser.last_error_extended_description)
  71.                 end
  72.             end
  73.             close (in_file)
  74.             print (parser.out)
  75.                 
  76.         end
  77. end -- class ROOT_CLASS
  78.