wx.richtext xml to/from plain text conversions

I am trying to write two functions, one to convert plain text to wx’s rich text XML format; and the other to convert the other way. I don’t need these functions to round-trip. I have a wxml_for_text(text) -> wxml function that works fine (although it seems verbose to me). But I cannot get the complementary text_for_wxml(wxml) -> text function to work.

Could anyone show me how to get text_for_wxml working? And ideally, show me how to shorten & simplify both functions if that’s possible?

Thanks.

I’ve attached t.py which runs with Python 3 and wxPython 4b2. For me the output is:

wxml_for_text

<?xml version="1.0" encoding="UTF-8"?> This and that. And there's more. And more. And <extra> &etc.

text_for_wxml

(‘A’, b’<?xml version="1.0" encoding="UTF-8"?>\n\n \n \n This and that.\nAnd there’s more.\n \n \n And more.\n \n \n And <extra> &etc.\n\n \n \n\n’)
(‘B’, ‘’)
(‘C’, ‘’)

I would have expected ‘B’ and ‘C’ to have plain text not empty strings.

t.py (1.13 KB)