title: is there a way to add an auto increment to an xml file when adding entries using php/simplexml?
body: <p>Here is my form for adding an entry.  What I want to do is when I submit the form to the php file to process and add the entry to the xml file, I want it to auto increment an ID tag I got in the xml file.</p>
  
  <pre><code>    &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Add an Entry to the Book Database&lt;/title&gt;
  &lt;style&gt;
  
  table{
      width:600px;
      border:5px dotted black;
      border-radius:10px;
      padding:10px;
      margin:10px;
      }
  
  &lt;/style&gt;
  &lt;/head&gt;
  
  
  &lt;body&gt;
  
  &lt;form action="addbook.php" method="post"&gt;
  &lt;table&gt;
  &lt;tr&gt;
      &lt;td&gt;Title:&lt;/td&gt; 
      &lt;td&gt;&lt;input type="text" name="title" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;Author:&lt;/td&gt; 
      &lt;td&gt;&lt;input type="text" name="author" /&gt;(&lt;strong&gt;Last Name, First Name&lt;/strong&gt;)&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;Publisher:&lt;/td&gt; 
      &lt;td&gt;&lt;input type="text" name="pub" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;Edition:&lt;/td&gt; 
      &lt;td&gt;&lt;input type="text" name="edition" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;Cover:&lt;/td&gt; 
      &lt;td&gt;&lt;input type="text" name="cover" /&gt;(&lt;em&gt;put file in directory "covers", this entry should be formatted "covers/*****.jpg" &lt;strong&gt;with the quotation marks&lt;/strong&gt;&lt;/em&gt;)&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;Genre:&lt;/td&gt; 
      &lt;td&gt;&lt;input type="text" name="genre" /&gt;(&lt;em&gt;if non-fiction, format as "Non-Fiction, *****" where **** is type of non-fiction.  Self-Help, Biographical, Philosophical, etc&lt;/em&gt;)&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;Have I Read?:&lt;/td&gt; 
      &lt;td&gt;&lt;input type="text" name="read" /&gt;(&lt;em&gt;"Yes", "No", "Partial"&lt;/em&gt;)
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;input type="submit" value="Add Book" /&gt;
  
  
  
  &lt;/form&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is the php form handler</p>
  
  <pre><code>&lt;?php
  
  $title = $_POST["title"];
  $author = $_POST["author"];
  $pub = $_POST["pub"];
  $edition = $_POST["edition"];
  $cover = $_POST["cover"];
  $genre = $_POST["genre"];
  $read = $_POST["read"];
  
  
  $xml = simplexml_load_file("books.xml");
  $addbook = $xml-&gt;addChild("book");
  $addbook-&gt;addChild("title", $title);
  $addbook-&gt;addChild("author", $author);
  $addbook-&gt;addChild("pub", $pub);
  $addbook-&gt;addChild("edition", $edition);
  $addbook-&gt;addChild("cover", $cover);
  $addbook-&gt;addChild("genre", $genre);
  $addbook-&gt;addChild("read", $read);
  
  $dom = new DOMDocument("1.0");
  $dom-&gt;preserveWhiteSpace = false;
  $dom-&gt;formatOutput = true;
  $dom-&gt;loadXML($xml-&gt;asXML());
  $dom-&gt;save("books.xml"); 
  
  header("Location:add_book_form.html");
  
  ?&gt;
  </code></pre>
  
  <p>and finally, here is a sample of the xml file</p>
  
  <pre><code>&lt;book&gt;
      &lt;title&gt;The Alphabet of Manliness&lt;/title&gt;
      &lt;author&gt;Maddox&lt;/author&gt;
      &lt;pub&gt;Citadel Press&lt;/pub&gt;
      &lt;edition&gt;First, 2006&lt;/edition&gt;
      &lt;cover&gt;"covers/alphabetmanliness.jpg"&lt;/cover&gt;
      &lt;genre&gt;Humor&lt;/genre&gt;
      &lt;read&gt;Yes&lt;/read&gt;
      &lt;id&gt;0016&lt;/id&gt;
  &lt;/book&gt;
  
  &lt;book&gt;
      &lt;title&gt;Atheist Manifesto&lt;/title&gt;
      &lt;author&gt;Onfray, Michel&lt;/author&gt;
      &lt;pub&gt;Arcade Publishing&lt;/pub&gt;
      &lt;edition&gt;First, 2007&lt;/edition&gt;
      &lt;cover&gt;"covers/atheistmanifesto.jpg"&lt;/cover&gt;
      &lt;genre&gt;Non-Fiction, Philosophy&lt;/genre&gt;
      &lt;read&gt;Partial&lt;/read&gt;
      &lt;id&gt;0017&lt;/id&gt;
  &lt;/book&gt;
  </code></pre>
  
  <p>Everything works fine in terms of adding title, author, etc.  I just need a way to check the last id, add one to it, and label the new entry with it.  is that possible with simplexml?</p>