I am not sure why you want to use an array. So the answer is a little more generic. But yes you can store XML nodes in variables including arrays.
$dom = new DOMDocument();
$created = [];
$created['plist'] = $dom->appendChild($dom->createElement('plist'));
$created['dict'] = $dom->createElement('dict');
$created['plist']->appendChild($created['dict']);
echo $dom->saveXml();
Output:
<?xml version="1.0"?>
<plist><dict/></plist>
appendChild()
returns the node it appended. So it is possible to use it directly on a createElement()
(or other create* call) and assign the result to a variable. So if the parent node is just stored in a variable the example will be cleaner.
$dom = new DOMDocument();
$plist = $dom->appendChild($dom->createElement('plist'));
$plist->appendChild($dom->createElement('dict'));
echo $dom->saveXml();
Now the DOM already is a data structure, you can use Xpath to fetch some nodes from it, why store the nodes in a second structure (the array)?
$dom = new DOMDocument();
$plist = $dom->appendChild($dom->createElement('plist'));
$plist->appendChild($dom->createElement('dict'));
$xpath = new DOMXpath($dom);
foreach ($xpath->evaluate('//*') as $node) {
var_dump($node->nodeName);
}
Output:
string(5) "plist"
string(4) "dict"