Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make DOMDocument write standalone=yes in PHP?

I'm using PHP5 to create XML files. I have code like this:

$doc = new DOMDocument();
...
$xml_content = $doc->saveXML();

The problem is that created XML code starts with a root node like this one:

<?xml version="1.0"?>

But I want it to be like this:

<?xml version="1.0" standalone="yes" ?>

I guess I need to call some function on $doc, but I can't figure out which one?

like image 852
Milan Babuškov Avatar asked Jan 16 '09 23:01

Milan Babuškov


People also ask

How to use DOMDocument in PHP?

PHP | DOMDocument getElementsByTagName() Function The DOMDocument::getElementsByTagName() function is an inbuilt function in PHP which is used to return a new instance of class DOMNodeList which contains all the elements of local tag name.

What is Domdoc?

A DomDocument is a container (variable/object) for holding an XML document in your VBA code. Just as you use a String variable to hold a strings value, you can use a DomDocument to hold an XML document. (for a complete list of a DomDocuments properties, see halfway down this page)


1 Answers

You want to set

$doc->xmlStandalone = true;

It's not a function of the class, it's a property so it's a little harder to find in the docs. You can read about it here.

like image 89
Ciaran McNulty Avatar answered Nov 03 '22 00:11

Ciaran McNulty