[Python] How to correctly use escape characters to write a mathematical string to a XML file...

Discussão em 'Python' iniciado por Stack, Novembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    I have an XML file which I am trying to edit using Python. This is an example of the content of the XML file:

    <?xml version="1.0" encoding="utf-8"?>
    <NEKTAR>
    <CONDITIONS>
    <FUNCTION NAME="Baseflow">
    <E VAR="u0" VALUE="(x>3) * (y <= 3) * 4 * x"/>
    </FUNCTION>
    </CONDITIONS>
    </NEKTAR>


    In the original file, the value for u0 is set to 0. Using Python, I want to change this value to the mathematical expression shown in the code-block. I have tried two approaches un-successfully:

    1. Write the in-equalities using the escape characters such as &lt; and &gt;
    2. Try to use CDATA

    What would be the right approach to do something like this using xml.etree.ElementTree ?

    Continue reading...

Compartilhe esta Página