Dave Smith - 2015-06-25 11:33:48 -
In reply to message 1 from Mick89
It is currently just a parser and does not have a method to change or write the data back.
I suppose those methods could be added, however it would not be nearly as efficient working on the returned array as working directly with the object where you would not even need a class...
$doc = new DOMDocument();
$doc = loadHTMLFile("filename.html");
$doc->getElementsByTagName('h2')->item(1)->nodeValue = 'My title';
$doc->getElementsByTagName('h2')->item(1)->setAttribute('id','myID');
I haven't tested that code, but in theory it should change the second instance of the h2 element to reflect the changes in your example. You may even be able to chain the setAttribute and change the nodeValue together on the same line. I have only recently started working with and learning the DOM.
Dave