πŸŽ‰ New: Top 75 PHP Interview Questions for 2026 β€” Free for all learners

PHP SimpleXML – Get Node/Attribute Values

P
php Guru
Β· Β· 1 min read Β·

πŸ“Œ Key Takeaways

  • PHP SimpleXML – Get Node/Attribute Values
  • PHP SimpleXML
  • More PHP XML Parser

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.

P
php Guru
PHP Developer & Technical Writer β€” phponline.in A seasoned PHP developer with 8+ years of experience in Laravel, MySQL, and REST APIs. Writes practical tutorials and career guides to help developers grow their skills and income. All salary data is researched from real job postings and developer surveys.
← Previous Post
PHP SimpleXML Parser
Next Post β†’
PHP XML Expat Parser