Print XML element attributes : simplexml_load_string « XML « PHP






Print XML element attributes

 
<?
$menu=<<<_XML_
<?xml version="1.0" encoding="utf-8" ?>
<rss version="0.91">
 <channel>
  <title>What's For Dinner</title>
  <link>http://example.com/</link>
  <description>choices</description>
  <item>
   <title>Feet</title>
   <link>http://example.com</link>
   <description>test</description>
  </item>
 </channel>
</rss>
_XML_;

$xml = simplexml_load_string($menu);


print 'This RSS feed is version ' . $xml['version'];
?>
  
  








Related examples in the same category

1.Accessing identically named elements
2.Adding attributes
3.Changing elements and attributes
4.Loop through children
5.Loading an XML document from a file
6.Fetching a remote XML document
7.Parsing XML in a string
8.Parsing an XML Document with SimpleXML
9.simplexml_load_file.php
10.Loading a remote XML document
11.Outputting XML
12.Using SimpleXML to extract data
13.Simple XML
14.Printing sub-element contents
15.Saving an XML document to a file