2017-07-20 21 views
0

を持つ要素を起動します。PHP - XMLでの名前空間 - 私は(PHPで生成された)XML形式の下に達成しようとしています名前空間

<ns0:XmlInterchange xmlns:ns0="http://www.website.com" xmlns:ext="http://www.website.com"> 
    <ns0:InterchangeInfo> 
     <ns0:Date>2017-06-28T11:33:15</ns0:Date> 
     <ns0:XmlType>Verbose</ns0:XmlType> 
     <ns0:Source> 
     <ns0:EnterpriseCode>DSV</ns0:EnterpriseCode> 
     <ns0:OriginServer>ESB</ns0:OriginServer> 
     </ns0:Source> 
     <ns0:EDIOrganisation EDICode="0"/> 
    </ns0:InterchangeInfo> 
</ns0:XmlInterchange> 

をだから、今、私が持っているすべてはこれです:

$xml = new DOMDocument('1.0', 'UTF-8'); 
$xml->formatOutput = true; 

$rss = $xml->createElement('ns0'); 
$rss->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:ns0', 'http://website.com'); 
$rss->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:ext', 'http://website.com'); 
$xml->appendChild($rss); 
この出力

<ns0 xmlns:ns0="http://website.com" xmlns:ext="http://website.com"/> 

上記の問題はXMLの始まりです。それはする必要があります:

<ns0:XmlInterchange xmlns:ns0="http://website.com" xmlns:ext="http://website.com"/> 

私はタグの先頭に:XmlInterchange名前空間を追加することができますどのように?

あなたが使用する必要があります

答えて

1

$rss = $xml->createElementNS('ns0', 'ns0:XmlInterchange'); 

代わりの

$rss = $xml->createElement('ns0'); 
関連する問題