πŸŽ‰ New: Top 75 PHP Interview Questions for 2026 β€” Free for all learners
Beginner ⏱ min read πŸ”„ Updated
Home β€Ί

Advertisement

SimpleXML is an extension for PHP that makes it easy to work with and get XML data.

PHP SimpleXML – Get Node Values

Get the values of the nodes from the file “example.xml”:

 

Here is XML file example

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<note>
<to>Ram</to>
<from>Shyam</from>
<heading>Message</heading>
<body>Lets do tracking this weekend!</body>
</note>

Get Node Values Example

<!DOCTYPE html>
<html>
<body>

<?php
$file_xml=simplexml_load_file(“note.xml”) or die(“Error: Cannot create object”);
echo $file_xml->to . “<br>”;
echo $file_xml->from . “<br>”;
echo $file_xml->heading . “<br>”;
echo $file_xml->body;
?>

</body>
</html>

Output

Ram
Shyam
Message
Lets do tracking this weekend!

More PHP XML Parser

Visit our PHP XML Parser Reference page to find out more about the XML Parser reference.

# Summary

Here is what you've learned in this lesson:

  • PHP SimpleXML - Get Node Values
  • More PHP XML Parser
πŸš€
Next up: PHP SimpleXML Parser

Continue to the next lesson and learn more about PHP SimpleXML Parser.

Start Next Lesson β†’

← Previous Post
PHP SimpleXML Parser
Next Post β†’
PHP XML Expat Parser