SlideShare a Scribd company logo
1 of 2
Download to read offline
Dalton Valadares – Universidade Federal de Campina Grande
How to populate a DB reading values from a XML file, with GRAILS?
-Suppose your XML is the following:
<Result totalLooseOffers="0" xsi:schemaLocation="http://somewhere.onthe.net/something.xsd">
<details>
<applicationID>37394759ds2k9a2k467626f3d</applicationID>
<date>2013-04-11T14:31:11.490-03:00</date>
<elapsedTime>1</elapsedTime>
<status>success</status>
<code>0</code>
<message>success</message>
</details>
<category concatenateCategoryName="false" hasOffer="false" isFinal="true" parentCategoryId="116" id="3661">
<thumbnail url="http://somewhere.onthe.net/something.jpg"/>
<links>
<link type="category" url="http://somewhere.onthe.net/something/51922611"/>
<link type="xml" url="http://somewhere.onthe.net/something/3739416878456f4/br/>
</links>
<name>Air conditioning </name>
<filters>
<filter name="Brand" id="1246">
<value value="Springer Carrier" id="47204"/>
<value value="LG" id="7018"/>
<value value="Consul" id="7017"/>
<value value="Midea" id="106986"/>
</filter>
<filter name="Type" id="1246">
<value value="Split" id="404"/>
<value value="Window" id="18"/>
<value value="Portable" id="707"/>
<value value="Multi-split" id="1066"/>
</filter>
.
.
.
</category>
-You want to save filters and values into DB;
-With your domain and controller classes created, you will have the save() method implemented;
-Create the class XML_Handler:
import java.awt.GraphicsConfiguration.DefaultBufferCapabilities;
import entities.Filter; //Your domain class for Filters
import entities.Value; //Your domain class for Values
import groovy.util.XmlParser
class XML_Handler {
public static run() {
def air_conditioning = new File("/path_to_file/air_conditioning.xml")
this.insertIntoDB(air_conditioning)
}
static insertIntoDB(File file) {
def my_handler = new XmlParser().parse(file)
my_handler.category.filters.filter.each {
Filter filter = new Filter();
filter.description = it.@name
filter.save(flush: true)
println "Filter: " + it.@name + " -----OK!"
it.value.each {
//the attribute filter receives the filter inserted before (created above)...
Value value = new Value(description: it.@value, filter: filter);
value.save(flush: true)
println " Value - " + it.@value + " -----OK!"
}
}
}
-Now, you just need to put the line below to be executed in any part of any controller (you can put a
button to do this function):
XML_Handler.run(); //when the code is executed, the values are inserted into DB
I hope it can help...

More Related Content

Similar to Xml to DB handler - grails tutorial

Semantic web support for POSH
Semantic web support for POSHSemantic web support for POSH
Semantic web support for POSHDinu Suman
 
Microsoft Accademic Cloud Tour Genova
Microsoft Accademic Cloud Tour GenovaMicrosoft Accademic Cloud Tour Genova
Microsoft Accademic Cloud Tour Genovaantimo musone
 
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)Pat Patterson
 
Ilmu sosial dasar - Pembuatan CV - HTML
Ilmu sosial dasar - Pembuatan CV  - HTMLIlmu sosial dasar - Pembuatan CV  - HTML
Ilmu sosial dasar - Pembuatan CV - HTMLIgnatiusAdityaKurnia
 
Simple run-time profiling quickie devoxx14
Simple run-time profiling quickie devoxx14Simple run-time profiling quickie devoxx14
Simple run-time profiling quickie devoxx14Joachim Van der Auwera
 
Data Con LA 2018 - Agile Integration Using an Enterprise Data Hub by Michael ...
Data Con LA 2018 - Agile Integration Using an Enterprise Data Hub by Michael ...Data Con LA 2018 - Agile Integration Using an Enterprise Data Hub by Michael ...
Data Con LA 2018 - Agile Integration Using an Enterprise Data Hub by Michael ...Data Con LA
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to BootstrapRon Reiter
 
Salesforce Lightning Data Services- Hands on Training
Salesforce Lightning Data Services- Hands on TrainingSalesforce Lightning Data Services- Hands on Training
Salesforce Lightning Data Services- Hands on TrainingSunil kumar
 
Using Apache Solr
Using Apache SolrUsing Apache Solr
Using Apache Solrpittaya
 
Building Viral Social Experiences
Building Viral Social ExperiencesBuilding Viral Social Experiences
Building Viral Social ExperiencesJonathan LeBlanc
 
Introduction to data visualisations with d3.js — Data Driven Documents
Introduction to data visualisations with d3.js — Data Driven DocumentsIntroduction to data visualisations with d3.js — Data Driven Documents
Introduction to data visualisations with d3.js — Data Driven DocumentsMichał Oniszczuk
 
Beyond full-text searches with Lucene and Solr
Beyond full-text searches with Lucene and SolrBeyond full-text searches with Lucene and Solr
Beyond full-text searches with Lucene and SolrBertrand Delacretaz
 

Similar to Xml to DB handler - grails tutorial (20)

Semantic web support for POSH
Semantic web support for POSHSemantic web support for POSH
Semantic web support for POSH
 
Microsoft Accademic Cloud Tour Genova
Microsoft Accademic Cloud Tour GenovaMicrosoft Accademic Cloud Tour Genova
Microsoft Accademic Cloud Tour Genova
 
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
 
Anex....,,,.
Anex....,,,.Anex....,,,.
Anex....,,,.
 
Anex....,,,.
Anex....,,,.Anex....,,,.
Anex....,,,.
 
Ilmu sosial dasar - Pembuatan CV - HTML
Ilmu sosial dasar - Pembuatan CV  - HTMLIlmu sosial dasar - Pembuatan CV  - HTML
Ilmu sosial dasar - Pembuatan CV - HTML
 
Simple run-time profiling quickie devoxx14
Simple run-time profiling quickie devoxx14Simple run-time profiling quickie devoxx14
Simple run-time profiling quickie devoxx14
 
Data Con LA 2018 - Agile Integration Using an Enterprise Data Hub by Michael ...
Data Con LA 2018 - Agile Integration Using an Enterprise Data Hub by Michael ...Data Con LA 2018 - Agile Integration Using an Enterprise Data Hub by Michael ...
Data Con LA 2018 - Agile Integration Using an Enterprise Data Hub by Michael ...
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to Bootstrap
 
Salesforce Lightning Data Services- Hands on Training
Salesforce Lightning Data Services- Hands on TrainingSalesforce Lightning Data Services- Hands on Training
Salesforce Lightning Data Services- Hands on Training
 
Check
CheckCheck
Check
 
Using Apache Solr
Using Apache SolrUsing Apache Solr
Using Apache Solr
 
Introduction to Html5
Introduction to Html5Introduction to Html5
Introduction to Html5
 
Building Viral Social Experiences
Building Viral Social ExperiencesBuilding Viral Social Experiences
Building Viral Social Experiences
 
Devices + Cloud: Using Windows Azure with Windows Phone, iOS, Android, ...
Devices + Cloud: Using Windows Azure with Windows Phone, iOS, Android, ...Devices + Cloud: Using Windows Azure with Windows Phone, iOS, Android, ...
Devices + Cloud: Using Windows Azure with Windows Phone, iOS, Android, ...
 
Introduction to data visualisations with d3.js — Data Driven Documents
Introduction to data visualisations with d3.js — Data Driven DocumentsIntroduction to data visualisations with d3.js — Data Driven Documents
Introduction to data visualisations with d3.js — Data Driven Documents
 
Doc
DocDoc
Doc
 
Doc
DocDoc
Doc
 
Schematron
SchematronSchematron
Schematron
 
Beyond full-text searches with Lucene and Solr
Beyond full-text searches with Lucene and SolrBeyond full-text searches with Lucene and Solr
Beyond full-text searches with Lucene and Solr
 

More from Dalton Valadares

Primeiros passos com Openstack
Primeiros passos com OpenstackPrimeiros passos com Openstack
Primeiros passos com OpenstackDalton Valadares
 
Performance Evaluation of an IEEE 802.11g Network in an Industrial Environment
Performance Evaluation of an IEEE 802.11g Network in an Industrial EnvironmentPerformance Evaluation of an IEEE 802.11g Network in an Industrial Environment
Performance Evaluation of an IEEE 802.11g Network in an Industrial EnvironmentDalton Valadares
 
802.11g Signal Strength Evaluation in an Industrial Environment (Elsevier Int...
802.11g Signal Strength Evaluation in an Industrial Environment (Elsevier Int...802.11g Signal Strength Evaluation in an Industrial Environment (Elsevier Int...
802.11g Signal Strength Evaluation in an Industrial Environment (Elsevier Int...Dalton Valadares
 
Towards 802.11g Signal Strength Estimation in an Industrial Environment: a Pr...
Towards 802.11g Signal Strength Estimation in an Industrial Environment: a Pr...Towards 802.11g Signal Strength Estimation in an Industrial Environment: a Pr...
Towards 802.11g Signal Strength Estimation in an Industrial Environment: a Pr...Dalton Valadares
 
Towards 802.11g Signal Strength Estimation in an Industrial Environment: a Pr...
Towards 802.11g Signal Strength Estimation in an Industrial Environment: a Pr...Towards 802.11g Signal Strength Estimation in an Industrial Environment: a Pr...
Towards 802.11g Signal Strength Estimation in an Industrial Environment: a Pr...Dalton Valadares
 
Internet das Coisas e a Indústria 4.0
Internet das Coisas e a Indústria 4.0Internet das Coisas e a Indústria 4.0
Internet das Coisas e a Indústria 4.0Dalton Valadares
 
Achieving Data Dissemination with Security using FIWARE and Intel Software Gu...
Achieving Data Dissemination with Security using FIWARE and Intel Software Gu...Achieving Data Dissemination with Security using FIWARE and Intel Software Gu...
Achieving Data Dissemination with Security using FIWARE and Intel Software Gu...Dalton Valadares
 
Internet das Coisas com Edgex Foundry
Internet das Coisas com Edgex FoundryInternet das Coisas com Edgex Foundry
Internet das Coisas com Edgex FoundryDalton Valadares
 
OPTEE on QEMU - Build Tutorial
OPTEE on QEMU - Build TutorialOPTEE on QEMU - Build Tutorial
OPTEE on QEMU - Build TutorialDalton Valadares
 
Presentation of my paper in the IEEE Symposium on Computer and Communications...
Presentation of my paper in the IEEE Symposium on Computer and Communications...Presentation of my paper in the IEEE Symposium on Computer and Communications...
Presentation of my paper in the IEEE Symposium on Computer and Communications...Dalton Valadares
 
Avaliação de Desempenho de uma Rede 802.11g em uma Usina Termoelétrica
Avaliação de Desempenho de uma Rede 802.11g em uma Usina TermoelétricaAvaliação de Desempenho de uma Rede 802.11g em uma Usina Termoelétrica
Avaliação de Desempenho de uma Rede 802.11g em uma Usina TermoelétricaDalton Valadares
 
Apresentação sobre o modelo de segurança OPC UA
Apresentação sobre o modelo de segurança OPC UAApresentação sobre o modelo de segurança OPC UA
Apresentação sobre o modelo de segurança OPC UADalton Valadares
 
Modelo de segurança OPC UA
Modelo de segurança OPC UAModelo de segurança OPC UA
Modelo de segurança OPC UADalton Valadares
 
Introdução à Gestão de projetos
Introdução à Gestão de projetosIntrodução à Gestão de projetos
Introdução à Gestão de projetosDalton Valadares
 
Integrating Fiware Orion, Keyrock and Wilma
Integrating Fiware Orion, Keyrock and WilmaIntegrating Fiware Orion, Keyrock and Wilma
Integrating Fiware Orion, Keyrock and WilmaDalton Valadares
 
Desenvolvimento Web com JSF
Desenvolvimento Web com JSFDesenvolvimento Web com JSF
Desenvolvimento Web com JSFDalton Valadares
 
Comparison of signal smoothing techniques for use in embedded system for moni...
Comparison of signal smoothing techniques for use in embedded system for moni...Comparison of signal smoothing techniques for use in embedded system for moni...
Comparison of signal smoothing techniques for use in embedded system for moni...Dalton Valadares
 

More from Dalton Valadares (20)

Primeiros passos com Openstack
Primeiros passos com OpenstackPrimeiros passos com Openstack
Primeiros passos com Openstack
 
Performance Evaluation of an IEEE 802.11g Network in an Industrial Environment
Performance Evaluation of an IEEE 802.11g Network in an Industrial EnvironmentPerformance Evaluation of an IEEE 802.11g Network in an Industrial Environment
Performance Evaluation of an IEEE 802.11g Network in an Industrial Environment
 
802.11g Signal Strength Evaluation in an Industrial Environment (Elsevier Int...
802.11g Signal Strength Evaluation in an Industrial Environment (Elsevier Int...802.11g Signal Strength Evaluation in an Industrial Environment (Elsevier Int...
802.11g Signal Strength Evaluation in an Industrial Environment (Elsevier Int...
 
Towards 802.11g Signal Strength Estimation in an Industrial Environment: a Pr...
Towards 802.11g Signal Strength Estimation in an Industrial Environment: a Pr...Towards 802.11g Signal Strength Estimation in an Industrial Environment: a Pr...
Towards 802.11g Signal Strength Estimation in an Industrial Environment: a Pr...
 
Towards 802.11g Signal Strength Estimation in an Industrial Environment: a Pr...
Towards 802.11g Signal Strength Estimation in an Industrial Environment: a Pr...Towards 802.11g Signal Strength Estimation in an Industrial Environment: a Pr...
Towards 802.11g Signal Strength Estimation in an Industrial Environment: a Pr...
 
Internet das Coisas e a Indústria 4.0
Internet das Coisas e a Indústria 4.0Internet das Coisas e a Indústria 4.0
Internet das Coisas e a Indústria 4.0
 
Achieving Data Dissemination with Security using FIWARE and Intel Software Gu...
Achieving Data Dissemination with Security using FIWARE and Intel Software Gu...Achieving Data Dissemination with Security using FIWARE and Intel Software Gu...
Achieving Data Dissemination with Security using FIWARE and Intel Software Gu...
 
Internet das Coisas com Edgex Foundry
Internet das Coisas com Edgex FoundryInternet das Coisas com Edgex Foundry
Internet das Coisas com Edgex Foundry
 
OPTEE on QEMU - Build Tutorial
OPTEE on QEMU - Build TutorialOPTEE on QEMU - Build Tutorial
OPTEE on QEMU - Build Tutorial
 
Presentation of my paper in the IEEE Symposium on Computer and Communications...
Presentation of my paper in the IEEE Symposium on Computer and Communications...Presentation of my paper in the IEEE Symposium on Computer and Communications...
Presentation of my paper in the IEEE Symposium on Computer and Communications...
 
Avaliação de Desempenho de uma Rede 802.11g em uma Usina Termoelétrica
Avaliação de Desempenho de uma Rede 802.11g em uma Usina TermoelétricaAvaliação de Desempenho de uma Rede 802.11g em uma Usina Termoelétrica
Avaliação de Desempenho de uma Rede 802.11g em uma Usina Termoelétrica
 
Apresentação sobre o modelo de segurança OPC UA
Apresentação sobre o modelo de segurança OPC UAApresentação sobre o modelo de segurança OPC UA
Apresentação sobre o modelo de segurança OPC UA
 
Modelo de segurança OPC UA
Modelo de segurança OPC UAModelo de segurança OPC UA
Modelo de segurança OPC UA
 
Introdução à Gestão de projetos
Introdução à Gestão de projetosIntrodução à Gestão de projetos
Introdução à Gestão de projetos
 
Integrating Fiware Orion, Keyrock and Wilma
Integrating Fiware Orion, Keyrock and WilmaIntegrating Fiware Orion, Keyrock and Wilma
Integrating Fiware Orion, Keyrock and Wilma
 
Programação C - Aula 1
Programação C - Aula 1Programação C - Aula 1
Programação C - Aula 1
 
Programação C - Aula 3
Programação C - Aula 3Programação C - Aula 3
Programação C - Aula 3
 
Programação C - Aula 4
Programação C - Aula 4Programação C - Aula 4
Programação C - Aula 4
 
Desenvolvimento Web com JSF
Desenvolvimento Web com JSFDesenvolvimento Web com JSF
Desenvolvimento Web com JSF
 
Comparison of signal smoothing techniques for use in embedded system for moni...
Comparison of signal smoothing techniques for use in embedded system for moni...Comparison of signal smoothing techniques for use in embedded system for moni...
Comparison of signal smoothing techniques for use in embedded system for moni...
 

Recently uploaded

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Xml to DB handler - grails tutorial

  • 1. Dalton Valadares – Universidade Federal de Campina Grande How to populate a DB reading values from a XML file, with GRAILS? -Suppose your XML is the following: <Result totalLooseOffers="0" xsi:schemaLocation="http://somewhere.onthe.net/something.xsd"> <details> <applicationID>37394759ds2k9a2k467626f3d</applicationID> <date>2013-04-11T14:31:11.490-03:00</date> <elapsedTime>1</elapsedTime> <status>success</status> <code>0</code> <message>success</message> </details> <category concatenateCategoryName="false" hasOffer="false" isFinal="true" parentCategoryId="116" id="3661"> <thumbnail url="http://somewhere.onthe.net/something.jpg"/> <links> <link type="category" url="http://somewhere.onthe.net/something/51922611"/> <link type="xml" url="http://somewhere.onthe.net/something/3739416878456f4/br/> </links> <name>Air conditioning </name> <filters> <filter name="Brand" id="1246"> <value value="Springer Carrier" id="47204"/> <value value="LG" id="7018"/> <value value="Consul" id="7017"/> <value value="Midea" id="106986"/> </filter> <filter name="Type" id="1246"> <value value="Split" id="404"/> <value value="Window" id="18"/> <value value="Portable" id="707"/> <value value="Multi-split" id="1066"/> </filter> . . . </category> -You want to save filters and values into DB; -With your domain and controller classes created, you will have the save() method implemented; -Create the class XML_Handler: import java.awt.GraphicsConfiguration.DefaultBufferCapabilities; import entities.Filter; //Your domain class for Filters import entities.Value; //Your domain class for Values import groovy.util.XmlParser class XML_Handler { public static run() { def air_conditioning = new File("/path_to_file/air_conditioning.xml") this.insertIntoDB(air_conditioning) } static insertIntoDB(File file) { def my_handler = new XmlParser().parse(file)
  • 2. my_handler.category.filters.filter.each { Filter filter = new Filter(); filter.description = it.@name filter.save(flush: true) println "Filter: " + it.@name + " -----OK!" it.value.each { //the attribute filter receives the filter inserted before (created above)... Value value = new Value(description: it.@value, filter: filter); value.save(flush: true) println " Value - " + it.@value + " -----OK!" } } } -Now, you just need to put the line below to be executed in any part of any controller (you can put a button to do this function): XML_Handler.run(); //when the code is executed, the values are inserted into DB I hope it can help...