What is SimpleXML?

Posted by admin | Posted in GoWeb99 | Posted on 10-08-2010-05-2008

0

SimpleXML is a new addition in PHP 5. It is an easy way of getting an element’s attributes and text, if you already know the XML document’s layout.

Compared to DOM or the Expat parser, SimpleXML is far simple. It just takes a few lines of code to read text data from an element.

SimpleXML converts the XML document into an object, like this:

  • Elements – Are converted to single attributes of the SimpleXMLElement object. When there’s more than one element on one level, they’re placed inside an array
  • Attributes – Are accessed using associative arrays, where an index corresponds to the attribute name
  • Element Data – Text data from elements are converted to strings. If an element has more than one text node, they will be arranged in the order they are found

SimpleXML is fast and easy to use when performing basic tasks like:

  • Reading XML files
  • Extracting data from XML strings
  • Editing text nodes or attributes

However, when dealing with advanced XML, like namespaces, you are better off using the Expat parser or the XML DOM.

Write a comment

Twitter Users
Enter your personal information in the form or sign in with your Twitter account by clicking the button below.