Tuesday, 9 June 2020

reading xml file with php

reading xml file with php
extensible mark up language
what is meant by xml
data transfer easily
u can create a tags easily
all tags are not predefined
it is a light weight
how tp print the xml data
users.xml
<users>
<user>
<name> rafique </name>
<age> 32 </age>
</user>
<user>
<name> vk</name>
<age> 31</age>
</user>
<user>
<name> vk1</name>
<age> 311</age>
</user>
<user>
<name> vkh</name>
<age> 311</age>
</user>
</users>
index.php
<php
$xml = simplexml_load_file('users.xml');
using this load the file to xml attribute
//echo $xml ->user[0] --> name;
it will print the user of o name
foreach($xml -->user as $user){
it will convert user with xml as user variable
echo $user >name.' is '. $user >age. '<br>';
print the user of name and age mentioned with >,
}
it will go to each and every thing
?>
//echo $xml ->user[0] --> name;
//echo $xml ->user[0] --> name;
writers.xml
<writers>
<writer>
<name> sri sri </name>
<time> 1910-1983 </time>
<book>
<name> mahaprasthanam </name>
<year> 1950 </year>
</book>
<book>
<name> rekka vippina revolutuin</name>
<year> 1971 </yer>
</book>
<book>
<name> paadavoyi bharateeyuda </name>
<year> 1983 </year>
</book>
</writer>

<writer>
<name> chalas</name>
<time> 1894-979 </time>
<book>
<name> maidanam </name>
<year> 1935 </year>
</book>
<book>
<name> bujigadu</name>
<year> 1953</yer>
</book>
<book>
<name> natakalu </name>
<year> 1960 </year>
</book>
</writer>
</writers>
xml.php
<?php
$xml = simplexml_load_file('writers.xml');
get the file and load to xml variable
foreach($xml --> writer as $writer){
convert
echo '<h3>' .$writer -> name .' ('. $writer -> time .')'.'</h3)';
in this xml inside of xml inside of xml
foreach ($wirter --> book as $book){
xml of wirter of name and xml of writer of time and sub for ech xml of book of name and xml of book year)
echo $book >name .' published in '.$book > year.' <br><br>';
}
}
?>

xml
simplexml_load_file
foreach
echo
simple format how to print the data of xml
xml
simplexml_load_file
foreach
foreach
how to print the xml data in display
how to access the file
how to write  afor each inside of for each
sub foreach from main for each



No comments:

Post a Comment