SlideShare uma empresa Scribd logo
1 de 2
Baixar para ler 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...

Mais conteúdo relacionado

Semelhante a 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
 

Semelhante a 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
 

Mais de 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
 

Mais de 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...
 

Último

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
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
🐬 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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Último (20)

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
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
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...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

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...