indexing description: "Objects that can generate/retrieve simple xml files% %i.e. one level deep. The format must be a valid build format." author: "" date: "$Date$" revision: "$Revision$" class GB_SIMPLE_XML_FILE_HANDLER inherit GB_CONSTANTS export {NONE} all end GB_FILE_CONSTANTS export {NONE} all end GB_XML_UTILITIES export {NONE} all end GB_SHARED_TOOLS export {NONE} all end CDATA_HANDLER export {NONE} all end feature -- Basic operations create_file (root_node_name: STRING; file_name: STRING; data: ARRAY [TUPLE [STRING, STRING]]) is -- Create an XML file `file_name', with a root node named `root_node_name' and the root node -- containing information given by `data'. require data_not_void: data /= Void root_node_name_not_void: root_node_name /= Void local formater: XM_FORMATTER document: XM_DOCUMENT root_element: XM_ELEMENT counter: INTEGER namespace: XM_NAMESPACE a_name_string, a_data_string: STRING do -- Create the root element. create namespace.make ("", "") create root_element.make_root (root_node_name, namespace) add_attribute_to_element (root_element, "xsi", "xmlns", Schema_instance) create document.make document.force_first (root_element) -- Add information in `names' and `data' to the file. from counter := 1 until counter > data.count loop a_name_string ?= (data @ counter) @ 1 a_data_string ?= (data @ counter) @ 2 check data_not_void: a_name_string /= Void and a_data_string /= Void end add_element_containing_string (root_element, a_name_string, enclose_in_cdata (a_data_string)) counter := counter + 1 end -- Format and save the document. create formater.make formater.process_document (document) write_file_to_disk (formater.last_string, file_name) end load_file (file_name: STRING): ARRAYED_LIST [TUPLE [STRING, STRING]] is -- Load file `file_name. `Result' contains the -- information contained in the file. -- Do nothing if the file is a directory. local file: RAW_FILE buffer: STRING do -- We now load the first 54 characters from the file, and -- check if they are what we expect a valid build file to hold. -- If not, then raise an error. -- 54 is completely arbitary, but enough to validate. create file.make_open_read (file_name) if not file.is_directory and not file.is_device then create buffer.make (file.count) file.start file.read_stream (file.count) file.close buffer := file.last_string -- This checks that the file actually is a valid Build file, the fact -- that 54 charaters are checked is arbitary. if buffer.count < 54 or (buffer.substring (1, 54).is_equal (xml_format + "