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

PHP SimpleXML – Get Node/Attribute Values

P
php Guru
Β· February 16, 2023 Β· 1 min read Β· Updated February 16, 2023

πŸ“Œ Key Takeaways

  • PHP SimpleXML – Get Node/Attribute Values
  • PHP SimpleXML
  • More PHP XML Parser
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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

Prove your humanity: 4   +   4   =