-- $Date: 2004/02/14 09:40:45 $
-- $Revision: 1.11 $
-- $Author: jcrocholl $

with Readers; use Readers;
with Token_Readers; use Token_Readers;

package body Encodings.MusicXML is

   -- Read encoding data from an XML reader.
   function Read_Encoding
     (XML : access XML_Reader-- Use this XML reader.
     return Encoding_Access    -- The newly created encoding.
   is
      Result : Encoding_Access := Create;
   begin
      while Descend(XML) loop
         Exit_Tag(XML);

         if Found(XML, "encoding-date") then
            Set_Encoding_Date(Result, Read_Data(XML));
         elsif Found(XML, "encoder") then
            Set_Encoder(Result, Read_Data(XML));
         elsif Found(XML, "software") then
            Set_Software(Result, Read_Data(XML));
         elsif Found(XML, "encoding-description") then
            Set_Encoding_Description(Result, Read_Data(XML));
         else
            XML_Expect_Error(XML, "/encoding",
              "encoding-date" / "encoder" /
              "software" / "encoding-description");
         end if;

         Exit_Element(XML);
      end loop;
      Exit_Tag(XML);

      return Result;
   end Read_Encoding;

   -- Write encoding data to an XML writer.
   procedure Write_Encoding
     (XML  : access XML_Writer-- Use this XML writer.
      This : access Encoding)   -- Write this encoding.
   is
   begin
      Start_Element(XML, "encoding");
      if Get_Software(This) /= "" then
         Write_Element(XML, "software", Get_Software(This));
      end if;
      if Get_Encoding_Date(This) /= "" then
         Write_Element(XML, "encoding-date", Get_Encoding_Date(This));
      end if;
      Close_Element(XML, "encoding");
   end Write_Encoding;

end Encodings.MusicXML;