Posts Tagged ‘XML’
PHP’s SimpleXML
SimpleXML is a PHP library extension available from PHP 5+. It enables PHP to easily access the data and structure of an SML document.
Previously DOM and DOM XML were used by PHP developers to parse XML. DOM and DOM XML requires tens of commands to do what what SimpleXML can do in a couple of lines. Furthermore, unlike DOM and DOM XML, SimpleXML creates a PHP onject which requires many fewer commands to access, read and write to the XML document structure.
The SimpleXML document needs to be created before and, if manipulated, re-created before it can be parsed using PHP. An XML document can be created from scratch using a simple PHP string..
$string = ""; $xmObject = simplexml_load_string($string);
Alternatively, a pre-created XML document can be used to create an object from file…
$xmlObject = simplexml_load_file('test.xml');
Once the script has made its additions/changes to the object, it can be exported back as XML using the following command…
$xml = new SimpleXMLElement($xmlObject);
That’s pretty much it.
MySQL’s new XML Functions
XML or Extensible Markup Language is an increasingly popular method of storing general information. To date its most widely used purpose has been feeds for various websites; but XML is much more than just an easy way to get the latest from your favourite blogs and news websites. MySQL has now introduced XML Functions allowing seamless integration of XML within a database.
A key part of this is XPath, a language specifically designed for reading information in an XML document. XPath can be used to navigate through elements and attributes in an XML document. XPath is used in conjunction with two MySQL functions which find and replace/return the data from the database.
- ExtractValue() uses two attributes to find and return specific information within an XML document in your MySQL Database.
- UpdateXML() uses three attributes to find and replace data within the XML document on the database.
I’ll be adding a post about SimpleXML for PHP which forgoes the need for a database all together.
















