The Simple xml GET is used for getting the node values from an xml file.
Following example shows how to get data from xml.
Hello.xml is an xml file, it can be accessed by php file -
PHP SimpleXML - Get Node Values
Get the node values from the "Hello.xml" file:
The output of the code above will be:
The following example gets the node value of the <title> element in the first and second <book> elements in the "books.xml" file:
Example :
output :
The following example loops through all the <book> elements in the "books.xml" file, and gets the node values of the <title>, <author>, <year>, and <price> elements:
Output :
The following example gets the attribute value of the "category" attribute of the first <book> element and the attribute value of the "lang" attribute of the <title> element in the second <book> element:
The output of the code above will be:
COOKING
en
The following example gets the attribute values of the <title> elements in the "books.xml" file:
The output of the code above will be:
en
en
en-us
en-us