【问题标题】:PHP - SOAP request - nest xml as param?PHP - SOAP 请求 - 将 xml 嵌套为参数?
【发布时间】:2018-08-01 07:17:56
【问题描述】:

我需要使我的 XML SOAP 请求的结构如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.fines.pl/api/contract">
    <SOAP-ENV:Body>
        <ns1:newApplicationRequest>
            <user_login>XYZ</user_login>
            <user_password>XYZ</user_password>
            <contract>
<?xml version="1.0" encoding="UTF-8"?>
<sof:Contract xmlns:s="http://www.fines.pl/simple" xmlns:sof="http://www.fines.pl/sof" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.fines.pl/sof model.xsd ">
    <product>
        <prefix>MOP</prefix>
    </product>
    <participants>
        <customers>
            <main_borrower>
                <personal_data>
                    <pesel>85050949761</pesel>
                    <firstname>Anna</firstname>
                    <lastname>Test</lastname>
                    <firstname_father></firstname_father>
                    <firstname_mother></firstname_mother>
                    <secondname />
                    <sex>female</sex>
                </personal_data>
                <contact_data>
                    <addresses>
                        <address>
                            <type>registered</type>
                            <street_name>Grunwaldzka</street_name>
                            <block_number>11</block_number>
                            <flat_number>5</flat_number>
                            <postal_code>80-100</postal_code>
                            <city>Gdańsk</city>
                        </address>
                    </addresses>
                    <phones_mobile>
                        <phone_mobile>
                            <type>personal</type>
                            <number>602200300</number>
                        </phone_mobile>
                    </phones_mobile>
                </contact_data>
                <incomes>
                    <income>
                        <type>employment</type>
                        <main_income>true</main_income>
                        <fixed_term_contract>false</fixed_term_contract>
                        <paychecks>
                            <paycheck>
                                <amount_net>
                                    <amount>1444.00</amount>
                                    <currency>PLN</currency>
                                </amount_net>
                                <type>base</type>
                            </paycheck>
                        </paychecks>
                    </income>
                </incomes>
                <household_pointer>/households.0</household_pointer>
            </main_borrower>
        </customers>
    </participants>
</sof:Contract></contract></ns1:newApplicationRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>

我已将我的 $params 变量设置为包含 user_loginuser_password 元素及其各自的值,但我不知道如何将这个 contract 参数设置为所需的内容。

$contract 变量提供XML 代码(我认为这可能是一种解决方法)会导致Fatal error: Uncaught SoapFault exception: [xml_structure] String could not be parsed as XML 错误。

非常感谢您解释如何做到这一点。

【问题讨论】:

    标签: php xml soap request wsdl


    【解决方案1】:

    你已经声明了两次&lt;?xml?&gt;,第一行一个,第八行第二个。这是我在 xml 方面看到的唯一错误。

    【讨论】:

    • 我引用的代码实际上是作为请求示例提供给我的,所以我似乎应该在contract 参数中为我嵌套一些XML 代码,或者他们只是给我发送了错误的示例?
    • 无论是什么,您都不能两次声明 xml,因此该示例很可能是错误的,如果您想进一步验证 xml,请尝试使用 xml 验证器。喜欢:w3schools.com/xml/xml_validator.asp 你也试过删除它。
    猜你喜欢
    • 2017-01-17
    • 1970-01-01
    • 2020-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-04
    • 1970-01-01
    相关资源
    最近更新 更多