PHP XML DOM Parser
The built-in DOM parser makes it possible to process XML documents in PHP.
The XML DOM Parser
It is a tree-based parser.
XML document fraction:
The DOM sees the XML above as a tree structure:
- Level 1: XML Document
- Level 2: Root element:
- Level 3: Text element: "text"
The XML File
Example for the XML file ("example.xml"):
Load and Output XML
Initialize the XML parser, load the xml, and output it:
Example - Load & Output XML
The output of the above example is
Test Best Example This is example Program
Output of the code above will be:
Tove Jani Reminder Don't forget me this weekend!
Looping through XML
Initialize the XML parser, load the XML, and loop through all elements of the
The output of the code above will be:
#text = to = Test #text = from = Best #text = heading = Example #text = body = This is example Program #text =