我無法用肥皂信封及正文標記生成XML生成與SOAP信封和body標籤XML,這裏是代碼,如何使用PHP
$rootElement = $XMLDoc->createElement('AddDetails');
$rootNode = $XMLDoc->appendChild($rootElement);
while($result_array = $result->fetch_assoc()) {
$StockCount++;
foreach($result_array as $key => $value) {
$value=trim($value);
if($value=="NULL" || $value=="" ||$value==-1){
$value="";
}
$value=htmlentities($value);//For validating & chars
$rootNode->appendChild($XMLDoc->createElement($key,$value));
}
}
產生密鑰和值的XML中的上述代碼像
<AddDetails>
<First_Name>TestFName</First_Name>
<Last_Name>TestLName</Last_Name>
</AddDetails>
,但我想生成XML像
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<AddDetails xmlns="http://tempuri.org/">
<First_Name>TestFName</First_Name>
<Last_Name>TestLName</Last_Name>
</AddDetails>
</soap:Body>
</soap:Envelope>
請幫助我。
您的源數據在哪裏?它包含什麼? – Parfait
來自數據庫的Sorce數據($ result_array = $ result-> fetch_assoc()) –