Sorry - but your code is incorrect.
The main problem is that the output XML has the 1003 student EMBEDDED INSIDE the 1001, which I do not think is the desired result.
my code produces:
<?xml version="1.0" encoding="utf-8"?>
<student id="1001"/><student id="1003"/>
which , I believe is what the OP wanted.
My goal ... to kill off the slow brain cells that are holding me back from synergizing my knowledge of vertically integrated mobile platforms in local cloud-based content management system datafication.