You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: write_xml.m
    path of file: ./repos/Image-Harmonization-Dataset-iHarmony4/Lalonde and Efros/utils/mycode/xml/load_xml
    
    the code of the file until where you have to start completion: % write_xml(filename, v, useAttributes)
% Write an XML structure to a file.  See load_xml.
% Author: Joe Rollo

function write_xml(filename, v, useAttributes,
    
function write_xml(filename, v, useAttributes, documentName)

if nargin <= 2
    useAttributes = 1;
    documentName = 'document';
end

if useAttributes
    
    % Save the structure with fields in attributes.
    names = fieldnames(v);
    if isempty(names(strcmp(names, 'document')))

        % No <document> tag.
        writeStructToXML(v, filename, documentName);
    else

       % Pass in the contents of the <document> tag; the write function will
       % add <document> and </document> automatically.
       writeStructToXML(v.document, filename, documentName); 
    end