PHP XMLLesson 73Free preview
PHP SimpleXML - Get
This lesson is part of PHP · All levels
Summary
Once the document is read, you need to extract information like child lists, attributes, number of elements, or specific sections using XPath. SimpleXML provides children(), count(), and xpath() for these needs. Conversion to string is enough with casting to make the value ready for use in PHP logic.
Key points
- Children() takes the list of child elements, count() calculates the repetition of an element.
- Xpath() look for nodes with XPath patterns such as //item[@id='2'].
- Attributes are read in square brackets: $element['attributes'].
- Casting converts the node into a normal text value.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.