2016-07-20 9 views
2

Ich habe versucht, alle möglichen Möglichkeiten, die leeren xmlns von Tags zu entfernen, bitte helfen, dieses Problem zu lösen.Entfernen leer xmlns = "" Attribut mit PHP

$XMLDoc = new DOMDocument('1.0', 'UTF-8'); 
$XMLDoc->preserveWhiteSpace = false; 
$XMLDoc->formatOutput = true; 
$soap = $XMLDoc->createElementNS('http://schemas.xmlsoap.org/soap/envelope/', 'soap:Envelope'); 
$XMLDoc->appendChild($soap); 
$soap->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); 
$soap->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:xsd', 'http://www.w3.org/2001/XMLSchema'); 
$soap->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:soap', 'http://schemas.xmlsoap.org/soap/envelope/'); 
$body = $XMLDoc->createElementNS('http://schemas.xmlsoap.org/soap/envelope/', 'soap:Body'); 
$XMLDoc->appendChild($body); 
include 'DBDetails.php'; 
$XMlQuery="SELECT `First_Name`, `Last_Name`, `Email`, `Pan_No`, `Res_address`, `Res_address2`, `Res_address3`, `Resi_type`, `Mobile`, `Res_City`, `Resi_City_other`, `Resi_City_other1`, `res_pin`, `Company_name`, `DateOfBirth`, `Designation`, `Emp_type`, `Monthly_income`, `card_held`, `Source_code`, `Promo_code`, `LEAD_DATE_TIME`, `PRODUCT_APPLIED_FOR`, `existingcust`, `LoanAmt`, `YrsinEmp`, `emi_paid`, `car_make`, `car_model`, `TypeOfLoan`, `IP_Address`, `Indigo_UniqueKey`, `Indigo_RequestFromYesNo` FROM `webservice` WHERE `Source_code` LIKE '$Sourcecode'"; 
$rowcount=-1; 
if($result=mysqli_query($conn,$XMlQuery)) { 
$rowcount=mysqli_num_rows($result); 
} 
if($rowcount>0){ 
$StockCount=-1; 
$rootElement = $XMLDoc->createElement('AddDetails'); 
$rootNode=$body->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=""; 
} 
$rootNode->appendChild($XMLDoc->createElement($key,$value)); 
} 
} 
mysqli_close($conn); 
} 
$XSLDoc = new DOMDocument('1.0', 'UTF-8'); 
$xslstr = '<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
     <xsl:output version="1.0" encoding="UTF-8" indent="yes" /> 
     <xsl:strip-space elements="*" />     
      <xsl:template match="/">  
       <xsl:apply-templates select="@*|node()" />  
      </xsl:template>     
      <xsl:template match="AddDetails"> 
      <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/"> 
        <xsl:copy-of select="*" /> 
       </AddDetails> 
       </soap:Body> 
      </soap:Envelope> 
      </xsl:template>     
     </xsl:transform>'; 
$XSLDoc->loadXML($xslstr); 
$proc = new XSLTProcessor; 
$proc->importStyleSheet($XSLDoc); 
$newXML = $proc->transformToXML($XMLDoc); 
echo $newXML; 

Es resultierende aus als

<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 xmlns="">TestFName</First_Name> 
<Last_Name xmlns="">TestLName</Last_Name> 
<Email xmlns="">[email protected]</Email> 
</AddDetails> 
</soap:Body> 
</soap:Envelope> 

würde Ich mag die XML-ähnliche

<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> 
<Email>[email protected]</Email> 
</AddDetails> 
</soap:Body> 
</soap:Envelope> 

Bitte helfen Sie mir generieren. Ich möchte den Code ohne leere xmlns generieren.

Antwort

0

Schnell und schmutzig Patch.

Kurz vor der letzten Zeile:

echo $newXML; 

hinzufügen:

$newXML = str_replace('xmlns=""', '', $newXML); 
+0

Dies ist keine Lösung, nur eine Bereinigung! Sie müssen der XSLT-Zeichenfolge dieselben xmlns-Anweisungen hinzufügen, um die leeren Standard-XML-Attribute zu vermeiden. – 4levels

0

Dies wird durch die fehlenden Namespace-Deklarationen in Ihrem XSLT-String verursacht wird.

Wenn die Namespaces aus Ihrem XML-Dokument nicht zu Ihrem XSLT-Dokument hinzugefügt werden, fügt der Prozessor die leeren standardmäßigen xmlns-Attribute hinzu.

Versuchen Sie, alle Namespaces aus der XML-Datei an Ihre XSLT-String hinzufügen, sollten diese die leeren xmlns Attribute Probleme lösen ..