Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of <Character> elements each with a name attributes and each enclosing its remarks.
All <Character> elements are to be enclosed in turn, in an outer <CharacterRemarks> element.

As an example, calling the function with the three names of:

April
Tam O'Shanter
Emily
And three remarks of:

Bubbly: I'm > Tam and <= Emily
Burns: "When chapman billies leave the street ..."
Short & shrift
Should produce the XML (but not necessarily with the indentation):

<CharacterRemarks>
    <Character name="April">Bubbly: I'm &gt; Tam and &lt;= Emily</Character>
    <Character name="Tam O'Shanter">Burns: "When chapman billies leave the street ..."</Character>
    <Character name="Emily">Short &amp; shrift</Character>
</CharacterRemarks>
The document may include an <?xml?> declaration and document type declaration, but these are optional. If attempting this task by direct string manipulation, the implementation must include code to perform entity substitution for the characters that have entities defined in the XML 1.0 specification.

Note: the example is chosen to show correct escaping of XML strings.
Note too that although the task is written to take two lists of corresponding data, a single mapping/hash/dictionary of names to remarks is also acceptable.

Note to editors: Program output with escaped characters will be viewed as the character on the page so you need to 'escape-the-escapes' to make the RC entry display what would be shown in a plain text viewer (See this).
Alternately, output can be placed in <lang xml></lang> tags without any special treatment.

 
//You need to use these units
uses
  Classes,
  Dialogs,
  XMLIntf,
  XMLDoc;
 
//..............................................
 
//This function creates the XML
function CreateXML(aNames, aRemarks: TStringList): string;
var
  XMLDoc: IXMLDocument;
  Root: IXMLNode;
  i: Integer;
begin
  //Input check
  if (aNames   = nil) or
     (aRemarks = nil) then
  begin
     Result:= '<CharacterRemarks />';
     Exit;
  end;
 
  //Creating the TXMLDocument instance
  XMLDoc:= TXMLDocument.Create(nil);
 
  //Activating the document
  XMLDoc.Active:= True;
 
  //Creating the Root element
  Root:= XMLDoc.AddChild('CharacterRemarks');
 
  //Creating the inner nodes
  for i:=0 to Min(aNames.Count, aRemarks.Count) - 1 do
  with Root.AddChild('Character') do
  begin
    Attributes['name']:= aNames[i];
    Text:= aRemarks[i];
  end;
 
  //Outputting the XML as a string
  Result:= XMLDoc.XML.Text;
end;
 
//..............................................
 
//Consuming code example (fragment)
var
  Names,
  Remarks: TStringList;
begin
  //Creating the lists objects
  Names:= TStringList.Create;
  Remarks:= TStringList.Create;
  try
    //Filling the list with names
    Names.Add('April');
    Names.Add('Tam O''Shanter');
    Names.Add('Emily');
 
    //Filling the list with remarks
    Remarks.Add('Bubbly: I''m > Tam and <= Emily');
    Remarks.Add('Burns: "When chapman billies leave the street ..."');
    Remarks.Add('Short & shrift');
 
    //Constructing and showing the XML
    Showmessage(CreateXML(Names, Remarks));
 
  finally
    //Freeing the list objects
    Names.Free;
    Remarks.Free;
  end;
end;
 
 