title: read and put xml elements in a list
body: <pre><code>&lt;Data&gt;
      &lt;List&gt;
      &lt;ID&gt;1&lt;/ID&gt;
      &lt;Name&gt;Peter&lt;/Name&gt;
      &lt;Contact&gt;Mobile&lt;/Contact&gt;
      &lt;Address&gt;US&lt;/Address&gt;
      &lt;/List&gt;
      .
      .
      .
  &lt;/Data&gt;
  </code></pre>
  
  <p>I have a huge xml in this format; I want to read the xml and put the xml elements into a list.</p>
  
  <p>How can we read and put elements in a list?
  here is the code which i tried for reading,but how to put that in a collection.please guide</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 xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;/head&gt;
  
  
  &lt;body&gt;
  &lt;?php
  $file = "note2.xml";
  $map_array = array(
      "BOLD"     =&gt; "B",
      "EMPHASIS" =&gt; "I",
      "LITERAL"  =&gt; "TT"
  );
  
  function startElement($parser, $name, $attrs) 
  {
      global $map_array;
      if (isset($map_array[$name])) {
          echo "&lt;$map_array[$name]&gt;";
          if (strpos((string) $movies-&gt;movie-&gt;title ,"PHP")!==false) {
      print 'My favorite movie.';
  }
  else{
      print 'new one';
      }
          echo "&lt;br /&gt;";
      }
  }
  
  function endElement($parser, $name) 
  {
      global $map_array;
      if (isset($map_array[$name])) {
          echo "&lt;/$map_array[$name]&gt;";
                  echo "&lt;br /&gt;";
      }
  }
  
  function characterData($parser, $data) 
  {
      echo $data;
  }
  
  $xml_parser = xml_parser_create();
  // use case-folding so we are sure to find the tag in $map_array
  xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
  xml_set_element_handler($xml_parser, "startElement", "endElement");
  xml_set_character_data_handler($xml_parser, "characterData");
  if (!($fp = fopen($file, "r"))) {
      die("could not open XML input");
  }
  
  while ($data = fread($fp, 4096)) {
      if (!xml_parse($xml_parser, $data, feof($fp))) {
          die(sprintf("XML error: %s at line %d",
                      xml_error_string(xml_get_error_code($xml_parser)),
                      xml_get_current_line_number($xml_parser)));
      }
  }
  xml_parser_free($xml_parser);
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>