我正在处理多个 API。请找到一些步骤。
Step1 我得到了第一个 API 的结果如下。 假设我收到了以下回复。
$xml = '<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Response
xmlns="http://schemas.martin-group.com/test">
<Result>
<![CDATA[
<AccountInfo><CusAccount Action="Add" AccountID="2046369" DesiredCycleID="0" Name=""
Corporation="" Cycle=""><AccountType><CusAccountType AccountTypeID="100001" Version="1"
AccountTypeCode="BUS " AccountType="Business" MonthlyBillingMethod="P" /></AccountType>
<InvoiceFormat><ICInvoiceFormat InvoiceFormatID="1" UserID="10490655"
AddressAdjustmentY="0" AddressWidth="3500"/></InvoiceFormat></CusAccount>
</AccountInfo>]]>
</Result>
</Response>
</soap:Body>
</soap:Envelope>';
第 2 步我已将 XML 转换为 XML 对象。
$soap = simplexml_load_string($xml);
$soap->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$object = $soap->xpath('//soap:Envelope/soap:Body')[0]->Response;
$cdata = $object->Result;
$cdata_as_xml = simplexml_load_string($cdata);
第 3 步我已经更新了一些节点的值,如下所示。
1. $cdata_as_xml->CusAccount['Action'] = 'Edit'
2. $cdata_as_xml->CusAccount['DesiredCycleID'] = '1'
3. $cdata_as_xml->CusAccount->AccountType->CusAccountType['AccountTypeID'] = '1000023'
如何获得纯 XML 而不是 XML 对象?
对此的任何帮助将不胜感激。
HUWWW