Hosted by
|
with Integer_Strings; use Integer_Strings;
with Readers; use Readers;
with Token_Readers; use Token_Readers;
with Writers; use Writers;
with Indent_Writers; use Indent_Writers;
package body Words.MusicXML is
function Read_Words
(XML : access XML_Reader)
return Words_Access
is
Result : Words_Access := Create;
begin
Assert_Tag_Name(XML, "words");
while not End_Of_Tag(XML) loop
Read_Attribute_Name(XML);
if Found(XML, "xml:lang") then
Read_Attribute_Value(XML);
Set_Lang(Result, Get_Token(XML));
elsif Found(XML, "relative-x") then
Read_Attribute_Value(XML);
Set_Relative_X(Result, To_Number(Get_Token(XML)));
elsif Found(XML, "relative-y") then
Read_Attribute_Value(XML);
Set_Relative_Y(Result, To_Number(Get_Token(XML)));
else
XML_Expect_Error(XML, "",
"xml:lang" / "relative-x" / "relative-y");
end if;
end loop;
Exit_Tag(XML);
Set_Text(Result, Read_Data(XML));
Exit_Element(XML);
return Result;
end Read_Words;
procedure Write_Words
(XML : access XML_Writer;
This : access Words)
is
begin
Write_Indent(XML);
Start_Tag(XML, "words");
if Get_Lang(This) /= "" then
Write_Attribute(XML, "xml:lang", Get_Lang(This));
end if;
if Get_Relative_Y(This) /= 0 then
Write_Attribute(XML, "relative-y", To_String(Get_Relative_Y(This)));
end if;
if Get_Relative_X(This) /= 0 then
Write_Attribute(XML, "relative-x", To_String(Get_Relative_X(This)));
end if;
Close_Tag(XML);
Write_Data(XML, Get_Text(This));
Write_Tag(XML, "/words");
New_Line(XML);
end Write_Words;
end Words.MusicXML;
|