downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/simplexmlelement.construct.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/class.simplexmlelement.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'simplexmlelement.construct.php',
   
1 => 'SimpleXMLElement::__construct',
  ),
 
'up' =>
  array (
   
0 => 'class.simplexmlelement.php',
   
1 => 'The SimpleXMLElement class',
  ),
 
'prev' =>
  array (
   
0 => 'simplexmlelement.children.php',
   
1 => 'SimpleXMLElement::children',
  ),
 
'next' =>
  array (
   
0 => 'simplexmlelement.getDocNamespaces.php',
   
1 => 'SimpleXMLElement::getDocNamespaces',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="simplexmlelement.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SimpleXMLElement::__construct</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.0.1)</p><p class="refpurpose"><span class="refname">SimpleXMLElement::__construct</span> &mdash; <span class="dc-title">
   Creates a new SimpleXMLElement object
  </span></p>

 </div>
 <a name="simplexmlelement.construct.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="classsynopsis">
   <div class="ooclass"><a href="class.simplexmlelement.php" class="classname">SimpleXMLElement</a></div>
    <div class="constructorsynopsis dc-description">
      <span class="methodname"><b>__construct</b></span>
      ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$data</tt></span>
     [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$options</tt></span>
     [, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$data_is_url</tt></span>
     [, <span class="methodparam"><span class="type">string</span> <tt class="parameter">$ns</tt></span>
     [, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$is_prefix</tt></span>
   ]]]] )</div>
 
  </div>
  <p class="para">
   Creates a new <a href="class.simplexmlelement.php" class="classname">SimpleXMLElement</a> object.
  </p>
 </div>


 <a name="simplexmlelement.construct.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">data</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       A well-formed XML string or the path or URL to an XML document if
       <i><tt class="parameter">data_is_url</tt></i>
 is <b><tt class="constant">TRUE</tt></b>.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">options</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       Optionally used to specify <a href="libxml.constants.php" class="link">additional
       Libxml parameters</a>.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">data_is_url</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       By default, <i><tt class="parameter">data_is_url</tt></i>
 is <b><tt class="constant">FALSE</tt></b>. Use <b><tt class="constant">TRUE</tt></b> to
       specify that <i><tt class="parameter">data</tt></i>
 is a path or URL to an XML
       document instead of <a href="language.types.string.php" class="type string">string</a> data.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">ns</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">is_prefix</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
      </p>
     </dd>

   
   </dl>
<p>
  </p>
 </div>


 <a name="simplexmlelement.construct.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns a <a href="class.simplexmlelement.php" class="type SimpleXMLElement">SimpleXMLElement</a> object representing
   <i><tt class="parameter">data</tt></i>
.
  </p>
 </div>


 <a name="simplexmlelement.construct.errors"></a><div class="refsect1 errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   Produces an <b><tt class="constant">E_WARNING</tt></b> error message for each error
   found in the XML data and throws an exception if errors were detected.
  </p>
  <div class="tip"><b class="tip">Tip</b>
   <p class="para">
    Use <a href="function.libxml-use-internal-errors.php" class="function">libxml_use_internal_errors()</a> to suppress all XML
    errors, and <a href="function.libxml-get-errors.php" class="function">libxml_get_errors()</a> to iterate over them
    afterwards.
   </p>
  </div>
 </div>


 <a name="simplexmlelement.construct.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 Create a SimpleXMLElement object</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">'example.php'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$sxe&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmlstr</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$sxe</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">movie</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]-&gt;</span><span style="color: #0000BB">title</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div><p>
  </p>
  <p class="para">
   </p><div class="example">
    <p><b>Example #2 Create a SimpleXMLElement object from a URL</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$sxe&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://example.org/document.xml'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">TRUE</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$sxe</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">asXML</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div><p>
  </p>
 </div>


 <a name="simplexmlelement.construct.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="function.simplexml-load-string.php" class="function" rel="rdfs-seeAlso">simplexml_load_string()</a> - Interprets a string of XML into an object</li>
    <li class="member"><a href="function.simplexml-load-file.php" class="function" rel="rdfs-seeAlso">simplexml_load_file()</a> - Interprets an XML file into an object</li>
    <li class="member"><a href="simplexml.examples-errors.php" class="xref">Dealing with XML errors</a></li>
    <li class="member"><a href="function.libxml-use-internal-errors.php" class="function" rel="rdfs-seeAlso">libxml_use_internal_errors()</a> - Disable libxml errors and allow user to fetch error information as needed</li>
   </ul><p>
  </p>
 </div>

</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites