<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >SimpleXMLElement->__construct()</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="SimpleXML functions" HREF="ref.simplexml.html"><LINK REL="PREVIOUS" TITLE="SimpleXMLElement->children()" HREF="function.simplexml-element-children.html"><LINK REL="NEXT" TITLE="SimpleXMLElement->getDocNamespaces()" HREF="function.simplexml-element-getdocnamespaces.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.simplexml-element-children.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.simplexml-element-getdocnamespaces.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.simplexml-element-construct" ></A >SimpleXMLElement->__construct()</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN209571" ></A ><P > (no version information, might be only in CVS)</P >SimpleXMLElement->__construct() -- Creates a new SimpleXMLElement object </DIV ><DIV CLASS="refsect1" ><A NAME="AEN209574" ></A ><H2 >说明</H2 >class <B CLASS="classname" >SimpleXMLElement</B > { <BR ></BR ><B CLASS="methodname" >__construct</B > ( string data [, int options [, bool data_is_url [, string ns [, bool is_prefix]]]] )<BR ></BR >}<P > Creates a new <B CLASS="classname" >SimpleXMLElement</B > object. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN209598" ></A ><H2 >参数</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >data</CODE ></DT ><DD ><P > A well-formed XML string or the path or URL to an XML document if <CODE CLASS="parameter" >data_is_url</CODE > is <TT CLASS="constant" ><B >TRUE</B ></TT >. </P ></DD ><DT ><CODE CLASS="parameter" >options</CODE ></DT ><DD ><P > Optionally used to specify <A HREF="ref.libxml.html#libxml.constants" >additional Libxml parameters</A >. </P ></DD ><DT ><CODE CLASS="parameter" >data_is_url</CODE ></DT ><DD ><P > By default, <CODE CLASS="parameter" >data_is_url</CODE > is <TT CLASS="constant" ><B >FALSE</B ></TT >. Use <TT CLASS="constant" ><B >TRUE</B ></TT > to specify that <CODE CLASS="parameter" >data</CODE > is a path or URL to an XML document instead of <A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A > data. </P ></DD ><DT ><CODE CLASS="parameter" >ns</CODE ></DT ><DD ><P > </P ></DD ><DT ><CODE CLASS="parameter" >is_prefix</CODE ></DT ><DD ><P > </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN209635" ></A ><H2 >返回值</H2 ><P > Returns a SimpleXMLElement object representing <CODE CLASS="parameter" >data</CODE >. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN209640" ></A ><H2 >错误/异常</H2 ><P > Produces an <TT CLASS="constant" ><B >E_WARNING</B ></TT > error message for each error found in the XML data and throws an exception if errors were detected. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN209644" ></A ><H2 >范例</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN209647" ></A ><P ><B >例 1. Create a SimpleXMLElement object</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /><br /></font><font color="#007700">include </font><font color="#DD0000">'example.php'</font><font color="#007700">;<br /><br /></font><font color="#0000BB">$sxe </font><font color="#007700">= new </font><font color="#0000BB">SimpleXMLElement</font><font color="#007700">(</font><font color="#0000BB">$xmlstr</font><font color="#007700">);<br />echo </font><font color="#0000BB">$sxe</font><font color="#007700">-></font><font color="#0000BB">movie</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">]-></font><font color="#0000BB">title</font><font color="#007700">;<br /><br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN209651" ></A ><P ><B >例 2. Create a SimpleXMLElement object from a URL</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /><br />$sxe </font><font color="#007700">= new </font><font color="#0000BB">SimpleXMLElement</font><font color="#007700">(</font><font color="#DD0000">'http://example.org/document.xml'</font><font color="#007700">, </font><font color="#0000BB">NULL</font><font color="#007700">, </font><font color="#0000BB">TRUE</font><font color="#007700">);<br />echo </font><font color="#0000BB">$sxe</font><font color="#007700">-></font><font color="#0000BB">asXML</font><font color="#007700">();<br /><br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN209654" ></A ><H2 >参见</H2 ><P > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><A HREF="function.simplexml-load-string.html" >simplexml_load_string</A ></TD ></TR ><TR ><TD ><A HREF="function.simplexml-load-file.html" >simplexml_load_file</A ></TD ></TR ></TBODY ></TABLE ><P ></P > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.simplexml-element-children.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.simplexml-element-getdocnamespaces.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >SimpleXMLElement->children()</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.simplexml.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >SimpleXMLElement->getDocNamespaces()</TD ></TR ></TABLE ></DIV ></BODY ></HTML >