Creating Attribute for Child Element?
===

XML and PHP noob here. I was following this tutorial: [Switch On The Code][1] and i'm wondering how to give a child element an attribute? 

**for instance he/she has the following:** 


    class Tutorial
    {
      public $author;
      public $title;
      public $date;
      public $categories;
      
      function __construct(
        $author, $title, $date, $categories)
      {
        $this->author = $author;
        $this->title = $title;
        $this->date = $date;
        $this->categories = $categories;
      }
    }


    $tutorials = array(
      new Tutorial(
        "The Reddest",
        "Silverlight and the Netflix API",
        "1/13/2009",
        array(
          "Tutorials",
          "Silverlight 2.0",
          "Silverlight",
          "C#",
          "XAML"
        )
      ),
        
      new Tutorial(
        "The Hairiest",
        "Cake PHP 4 - Saving and Validating Data",
        "1/12/2009",
        array(
          "Tutorials",
          "CakePHP",
          "PHP"
        )
      ),
      
      new Tutorial(
        "The Tallest",
        "Silverlight 2 - Using initParams",
        "1/6/2009",
        array(
          "Tutorials",
          "Silverlight 2.0",
          "Silverlight",
          "C#",
          "HTML"
        )
      ),
      
      new Tutorial(
        "The Fattest",
        "Controlling iTunes with AutoHotkey",
        "12/12/2008",
        array(
          "Tutorials",
          "AutoHotkey",
        )
      )
    );


    header("Content-Type: text/plain");

    //create the xml document
    $xmlDoc = new DOMDocument();
    
    //create the root element
    $root = $xmlDoc->appendChild(
              $xmlDoc->createElement("RecentTutorials"));
            
    //make the output pretty
    $xmlDoc->formatOutput = true;
    


    foreach($tutorials as $tut)
    {
      //create a tutorial element
      $tutTag = $root->appendChild(
                  $xmlDoc->createElement("Tutorial"));
                
      //create the author attribute
      $tutTag->appendChild(
        $xmlDoc->createAttribute("author"))->appendChild(
          $xmlDoc->createTextNode($tut->author));
    
      //create the title element
      $tutTag->appendChild(
        $xmlDoc->createElement("Title", $tut->title));
    
      //create the date element
      $tutTag->appendChild(
        $xmlDoc->createElement("Date", $tut->date));
    }

**which produces:** 


    <?xml version="1.0"?>
    <RecentTutorials>
      <Tutorial author="The Reddest">
        <Title>Silverlight and the Netflix API</Title>
        <Date>1/13/2009</Date>
      </Tutorial>
      <Tutorial author="The Hairiest">
        <Title>Cake PHP 4 - Saving and Validating Data</Title>
        <Date>1/12/2009</Date>
      </Tutorial>
      <Tutorial author="The Tallest">
        <Title>Silverlight 2 - Using initParams</Title>
        <Date>1/6/2009</Date>
      </Tutorial>
      <Tutorial author="The Fattest">
        <Title>Controlling iTunes with AutoHotkey</Title>
        <Date>12/12/2008</Date>
      </Tutorial>
    </RecentTutorials>


**what if i want this instead:**

    <?xml version="1.0"?>
    <RecentTutorials>
      <Tutorial author="The Reddest">
        **<Title type = string >Silverlight and the Netflix API</Title>** 

***> Title has an attribute!!***

        <Date>1/13/2009</Date>
      </Tutorial>
      <Tutorial author="The Hairiest">
        <Title type = string>Cake PHP 4 - Saving and Validating Data</Title>
        <Date>1/12/2009</Date>
      </Tutorial>
      <Tutorial author="The Tallest">
        <Title type = string>Silverlight 2 - Using initParams</Title>
        <Date>1/6/2009</Date>
      </Tutorial>
      <Tutorial author="The Fattest">
        <Title type = string>Controlling iTunes with AutoHotkey</Title>
        <Date>12/12/2008</Date>
      </Tutorial>
    </RecentTutorials>

  [1]: http://www.switchonthecode.com/tutorials/creating-xml-documents-in-php