title: Groovy XMLParser & XMLSlurper
body: <p>I am working on a groovy xml exercise &amp; as per the problem, i need to write 2 methods:</p>
  
  <p>readFileContent(fileName) - This method is used to read the content from file(xml file) and return that file's content as string.</p>
  
  <p>loadStudents(xmlString) - This method is used to generate the student list using the parameterized xml string(Please parse that xml string(use xmlSlurper) and create the student object and add to the studentList).</p>
  
  <p>i tried using xmlparser.parse(fileName) to create my xmlString, and then used xmlSlurper.parseText in loadStudent method. however, getting content is not allowed prolong error.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>def xmlString  = new XmlParser().parse(fileName)
  def students = new XmlSlurper().parseText(xmlString)
  </code></pre>
  
  <p>here's xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;students&gt;
  &lt;student&gt;
  &lt;id&gt;1&lt;/id&gt;
  &lt;registerNumber&gt;1225&lt;/registerNumber&gt;
  &lt;name&gt;Madison&lt;/name&gt;
  &lt;/student&gt;
  &lt;student&gt;
  &lt;id&gt;3&lt;/id&gt;
  &lt;registerNumber&gt;4152&lt;/registerNumber&gt;
  &lt;name&gt;Paul&lt;/name&gt;
  &lt;/student&gt;
  &lt;student&gt;
  &lt;id&gt;5&lt;/id&gt;
  &lt;registerNumber&gt;1785&lt;/registerNumber&gt;
  &lt;name&gt;Sam&lt;/name&gt;
  &lt;/student&gt;
  &lt;student&gt;
  &lt;id&gt;2&lt;/id&gt;
  &lt;registerNumber&gt;4158&lt;/registerNumber&gt;
  &lt;name&gt;Jason&lt;/name&gt;
  &lt;/student&gt;
  &lt;student&gt;
  &lt;id&gt;4&lt;/id&gt;
  &lt;registerNumber&gt;1674&lt;/registerNumber&gt;
  &lt;name&gt;Harry&lt;/name&gt;
  &lt;/student&gt;
  &lt;/students&gt;
  </code></pre>
  
  <p>Note: i know i can just directly parse the file in xmlSlurper &amp; it works fine. however, this is online exercise &amp; needs to be done using both methods.</p>
  
  <p>Thanks in advance.</p>