title: SimpleXMLElement (PHP) throwing error on XML root attributes
body: <p>I am working on a project that will take XML data submitted through a textarea input in a form then extract the data and throw it into a database. I am getting errors about the attribute in the root field of my XML (it is the same schema each time, but with different values). If i remove these attributes it works fine, but I don't want to have to remove these attributes each I time I go to send the data to the script.</p>
  
  <p>here is a sample of my data and code I am using (the part that is giving me errors):</p>
  
  <pre><code>&lt;raid generatedFrom="HeadCount" version="1.7.4"&gt;
  --snip--
  &lt;/raid&gt;
  </code></pre>
  
  <p>If I post the data as such, i get errors such as:</p>
  
  <pre><code>Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : AttValue: " or ' expected in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
  
  Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: &lt;raid generatedFrom=\"HeadCount\" version=\"1.7.4\"&gt; in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
  
  Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
  
  Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : attributes construct error in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
  
  Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: &lt;raid generatedFrom=\"HeadCount\" version=\"1.7.4\"&gt; in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
  
  Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
  
  Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : Couldn't find end of Start Tag raid line 1 in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
  
  Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: &lt;raid generatedFrom=\"HeadCount\" version=\"1.7.4\"&gt; in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
  
  Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
  
  Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : Extra content at the end of the document in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
  
  Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: &lt;raid generatedFrom=\"HeadCount\" version=\"1.7.4\"&gt; in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
  
  Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
  
  Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php:13 Stack trace: #0 /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php(13): SimpleXMLElement-&gt;__construct('&lt;raid generated...') #1 {main} thrown in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
  </code></pre>
  
  <p>If I remove the attributes from the root node then it works fine with no errors. </p>
  
  <p>Here is the code I am using to take and display it;</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php
  if(isset($_POST['h_input']))
  {
      //echo 
      //$xml_d = file_get_contents('php://input');
      $xml_d = $_POST['h_input'];
      //print_r($xml_d);
      $xml = new SimpleXMLElement($xml_d);
  
      echo $xml-&gt;zone . "&lt;br /&gt;";
      foreach ($xml-&gt;players-&gt;player as $player) {
          echo $player-&gt;name . "&lt;br /&gt;";
      }
  } else {
  ?&gt;
  &lt;form action="headcount.php" method="post" name="headcount"&gt;
  &lt;textarea rows="10" cols="30" name="h_input"&gt;
  &lt;/textarea&gt;
  &lt;input type="submit" /&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>