首先简单介绍一下SimpleXMLElement类
finalpublicSimpleXMLElement::__construct() (string$data [, int$options = 0 [,bool $data_is_url = false [,string$ns = "" [, bool $is_prefix = false ]]]] )Creates a new SimpleXMLElement object
A well-formed XML string or the path or URL to an XML document ifdata_is_url isTRUE.
Optionally used to specify additional Libxml parameters.
By default, data_is_url is FALSE. Use TRUE to specify that data is a path or URL to an XML document instead ofstring data
1)第一种
<?
$xml=new SimpleXMLElement("demo01.xml",null,true);
2)第二种【传参是字符串】
<?php
$str = <<<xml
<student>
<name>zhangsan</name>
<age>30</age>
</student>
xml;
$xml=new SimpleXMLElement($str);
3)第三种【通过simplexml_load_file方法可以返回SimpleXMLElement类的对象,完成实例化】
<?
$xml=simplexml_load_file("demo01.xml");