1

Possible Duplicate:
Import XML into a Grails Domain Class

say am having the xml file like below, Now i want to insert these firstname, deptname and empid into the database using grails can anyone suggest an idea in this.

<employees>
<employee>
<firstname>Marios</firstname>
<deptname>ITdepartment</deptname>
<empid>123</empid>
</employee>
<employee>
<firstname>Ben</firstname>
<deptname>Management</deptname>
<empid>124</empid>
</employee>
</employees>

Community
  • 1
  • 1
Sabarish
  • 1,184
  • 3
  • 14
  • 35
  • 2
    There are plenty of articles out there, you should be able to get ideas just by searching the web. I would recommend you start off with [this article](http://stackoverflow.com/questions/how-to-ask). After that, you can create a [domain class in GORM](http://grails.org/doc/latest/guide/GORM.htm) for employee. Then use [XML Slurper](http://groovy.codehaus.org/Reading+XML+using+Groovy's+XmlSlurper) to parse the XML and populate your domain object before you save it to the database. – chrislatimer Aug 21 '12 at 14:45
  • This should point you in the right direction: [xml][1] [1]: http://stackoverflow.com/questions/1519395/import-xml-into-a-grails-domain-class – Universitas Aug 21 '12 at 16:30

1 Answers1

1

Thank you all, I got the answer how to do that am posting here for others for their knowledge if changes required any can suggest me

def Employee = new XmlParser().parse("Your Xml file path")
def set1 = sql.dataSet("Your field name in Xml")
Employee.employee.each {
def firstname = it.firstname.text()
def deptname = it.deptname.text()
def empid = it.empid.text()
set1.add(first_name:firstname,dept_name:deptname,emp_id:empid)
}

Sabarish
  • 1,184
  • 3
  • 14
  • 35