php使用simplexml_load_file加载XML文件并显示XML的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了php使用simplexml_load_file加载XML文件并显示XML的方法。分享给大家供大家参考。具体实现方法如下:

<?php
  $xml = simplexml_load_file("sample.xml");
  echo htmlspecialchars($xml->asXML());
?>

sample.xml文件内容如下

<library>
  <book>
   <title>A</title>
   <author gender="female">B</author>
   <description>C</description>
  </book>
  <book>
   <title>C</title>
   <author gender="male">D</author>
   <description>E</description>
  </book>
  <book>
   <title>F</title>
   <author gender="male">G</author>
   <description>H</description>
  </book>
</library>

希望本文所述对大家的php程序设计有所帮助。

相关文章

PHP 各种排序算法实现代码

复制代码 代码如下:<?php // 功能: PHP实现各种排序算法 // Author: windlike // Datetime: 2007-06-09 // 冒泡排序 fun...

PHP单例模式实例分析【防继承,防克隆操作】

本文实例讲述了PHP单例模式。分享给大家供大家参考,具体如下: <?php //单列模式 // //1.普通类 // class singleton{ // } //...

php校验表单检测字段是否为空的方法

本文实例讲述了php校验表单检测字段是否为空的方法。分享给大家供大家参考。具体如下: php校验表单,检测字段是否为空,当表单中有未填写的字段,则会显示错误信息。 <html&...

PHP 图像尺寸调整代码

复制代码 代码如下: /********************** *@filename - path to the image *@tmpname - temporary path...

基于asp+ajax和数据库驱动的二级联动菜单

index.asp 页面代码 复制代码 代码如下: <!--#include file="conn.asp" --> <% set cmd = conn.execute...