Extension in Basic macro script: some characters inside the script would cause problem because script is inside an XML file

I have already reported a bug which is identified as NOTABUG. So, I’m going to ask here to get some help:

https://bugs.documentfoundation.org/show_bug.cgi?id=159522

My question is how to include the StarBasic macro script inside an extension’s XML file like Module1.xba without worrying about some characters like <>, <=, and <=> interfering with the XML file format. Is there a convenient way? For example, linking to an external Basic script file from within the XML file. Or any other way?

Hallo

from xml.sax.saxutils import escape

basic_source_code =(
"""
# todo for you
""")

xml_basic_frame =(
f"""<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Module1" script:language="StarBasic">

{escape(basic_source_code, {"'":"&apos;",'"': "&quot;"})}

</script:module>""")
1 Like