0

I am trying to achieve below format in XML (generated with PHP):

<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>

So, right now, all I have is this:

$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);

Which outputs this:

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

The problem above is the beginning of the XML. It needs to be:

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

How can I add the :XmlInterchange namespace to the beginning of the tag?

1 Answer 1

1

You should use :

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

instead of

$rss = $xml->createElement('ns0');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.