PHP XMLLesson 72Free preview
PHP SimpleXML Parser
This lesson is part of PHP · All levels
Summary
SimpleXML loads the XML document into SimpleXMLElement objects so that each element can be read as a property. The simplexml_load_file() function is used for files, while simplexml_load_string() is used for XML strings. The value read is string-type so it needs to be converted by itself if it is to be calculated as a number.
Key points
- Simplexml_load_file() and simplexml_load_string() return the object or FALSE if it fails.
- The child element is read by a -> sign like $xml->title.
- Repeated element access is done via foreach or an index, e.g. $xml->item[1].
- Read attributes using square brackets, such as $xml['id'].
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.