You seem to be confusing the SimpleXML and DOM extensions. While they are both implemented on top of the same parser, and can be switched between easily using dom_import_simplexml()
and simplexml_import_dom()
, that doesn't mean you can simply call methods which work on one on objects created by the other.
In your case, you are primarily using the DOM, so you need to add your attribute using the appropriate DOM functions, specifically ->createAttributeNS()
and ->appendChild()
.
I think the code you need is this:
$ParskCeturksnis = $DOM->createElement('ParskCeturksnis');
$ParskCeturksnis->appendChild($DOM->createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:nil"));
$DokPVNv4->appendChild($ParskCeturksnis);