如何将动态值传递给xml文件?

2024-09-29 03:40:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我们在python中使用soapis。我们需要动态地传递请求xml文件中的值。在

test.xml文件:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <Add xmlns="http://tempuri.org/">
            <intA>3</intA>
            <intB>4</intB>
        </Add>
    </Body>
</Envelope>

Python脚本:

^{pr2}$

我们需要从python动态传递intA和intB。在


Tags: 文件orgtestaddhttp动态bodyxml
1条回答
网友
1楼 · 发布于 2024-09-29 03:40:28

可以使用格式字符串方法。可以在xml文件中指定位置/关键字参数。在进行请求调用时,可以传递这些参数的值。在

这是你的测试.xml文件应如下所示:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <Add xmlns="http://tempuri.org/">
            <intA>{first_number}</intA>
            <intB>{second_number}</intB>
        </Add>
    </Body>
</Envelope>

在Python脚本中,可以加载xml文件,在发出posts请求时,可以传递参数。方法如下:

^{pr2}$

相关问题 更多 >