如何转换为PHP输出?
<?xml version="1.0" encoding="iso-8859-1"?> <employee> <name>Mark</name> <age>27</age> <salary>$5000</salary> </employee> <employee> <name>Jack</name> <age>25</age> <salary>$4000</salary> </employee> <employee> <name>nav</name> <age>25</age> <salary>$4000</salary> </employee>
<?PHP $doc = new DOMDocument(); $doc->load( 'test1.xml' );//xml file loading here $employees = $doc->getElementsByTagName( "employee" ); foreach( $employees as $employee ) { $names = $employee->getElementsByTagName( "name" ); $name = $names->item(0)->nodeValue; $ages= $employee->getElementsByTagName( "age" ); $age= $ages->item(0)->nodeValue; $salaries = $employee->getElementsByTagName( "salary" ); $salary = $salaries->item(0)->nodeValue; echo "<b>$name - $age - $salary\n</b><br>"; } ?>
//这样的出来马克 – 27 – $5000杰克 – 25 – $4000nav – 25 – $4000@H_502_10@