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 file: KL_TEXT_OUTPUT_FILE do -- Create the root element. create namespace.make_default create document.make_with_root_named (root_node_name, namespace) root_element := document.root_element add_attribute_to_element (root_element, "xsi", "xmlns", Schema_instance) -- 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 file.make (file_name) file.open_write file.put_string (xml_format) create formater.make formater.set_output (file) formater.process_document (document) file.close 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 + "