data = """<X>
    <X03>3</X03>
    <X02>2</X02>
    <A>
        <A02>Y</A02>
        <A01>X</A01>
        <A03>Z</A03>
    </A>
    <X01>1</X01>
    <B>
        <B01>Z</B01>
        <B02>X</B02>
        <B03>C</B03>
    </B>
</X>"""
doc = etree.XML(data, etree.XMLParser(remove_blank_text=True))
for parent in doc.xpath('//*[./*]'):
    parent[:] = sorted(parent, key=lambda x: x.tag)
print(etree.tostring(doc, pretty_print=True))
LXML - Sorting Tag Order