Loading a Document

Where DOMDocument is the central class in the DOM extension, SimpteXMLEtement is its counterpart in the SimpleXML extension. Loading a markup document is as simple as specifying it via the class constructor.

<?php
// Loads markup already contained within a string
$sxe = new SimpleXMLElement($markupString);

// Loads markup contained within an external file
$sxe = new SimpleXMLElement($filePath, null, true);
?>

The constructor’s second parameter (specified as null in the second example shown above) allows for further configuration of the instance. For documents with less than valid markup, using the value LIBXML_NOERROR | LIBXML_NOWARNING for this parameter may be useful as it suppresses error and warning reports.

Finally, the third parameter used in the second constructor call is set to true to indicate that $filePath is in fact a path to a file containing markup rather than the markup itself.


© SimpleXML Extension — Web Scraping

>>> Back to TABLE OF CONTENTS <<<
Category: Article | Added by: Marsipan (03.09.2014)
Views: 327 | Rating: 0.0/0
Total comments: 0
avatar