def marker_xml(marker, marker_words, w_ids, attrib, value):
    """Returns marker xml given words and word ids.

    For headers, this function returns a byte string like:
    <header level="1" text="Some Arabic text">
      <ref id="145795"/>
      <ref id="145796"/>
      <ref id="145797"/>
      <ref id="145798"/>
      <ref id="145799"/>
    </header>

   And for Quran/Hadith quotes:
   <quote type="quran|hadith" text="Some Arabic text">
     <ref id="3824"/>
     <ref id="3825"/>
     <ref id="3826"/>
     <ref id="3827"/>
     <ref id="3828"/>
    </quote>
    """
    xml = []
    xml.append('<{} {}="{}" text="{}">\n'.format(marker, attrib, value,
               ' '.join(marker_words)).encode('utf-8'))
    for w_id in w_ids:
        xml.append('  <ref id="{}"/>\n'.format(w_id).encode('utf-8'))
    xml.append('</{}>\n'.format(marker).encode('utf-8'))

    return b''.join(xml)