Kashif Roshen Kashif Roshen - 24 days ago 7
PHP Question

How to change the default soap header?

I am using this code to set the header.

$root = new \SimpleXMLElement('<S:Header/>');


and I get this error.

SimpleXMLElement::__construct(): namespace error : Namespace prefix S on Header is not defined.

Does anybody know How to solve this? :/ Thanks in advance :)

Answer

You need to define namespace for prefix S.

$root = new SimpleXMLElement('<S:Header></S:Header>', LIBXML_NOERROR, false, 'S', true);
//add namespace attribute into root element
$root->addAttribute('xmlns:xmlns:S','mynamespace');

print_r($root->asXML());