SlideShare a Scribd company logo
1 of 22
Download to read offline
XML Parsing Using JAXB
● Object (DOM, JDOM….etc)
● PUSH (SAX)
● PULL(Stax)
● JAXB(Java Architecture for XML Binding)
● Defines an API for reading and writing Java objects to and from XML
documents.
● Don't need to be aware of XML parsing techniques
● No extra dependency needed (its inside JDK)
● Used as a standard in many cases
XML JAXB
Java
Objects
●
●
JAXB uses annotations to indicate the central elements.
Annotation Definition
@XmlRootElement(namespace = "namespace") Define the root element for an XML tree
@XmlType(propOrder = { "field2", "field1",.. }) Allows to define the order in which the fields are written in
the XML file
@XmlElement Define the XML element which will be used.
@XmlAttribute Define the attribute of an element
Marshalling UnMarshalling
XML :
<?xml version="1.0" encoding="UTF-8"?>
<booking xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance">
<company name="ACME Consulting">
<address>10 Coyote Avenue, Arizona, USA</address>
<contact name="Duke" email="duke@acme.com"
telephone="1234567890"/>
</company>
<student firstName="Jane" surname="Dow"/>
<student firstName="John" surname="Doe"/>
</booking>
XSD :
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="booking" type="courseBooking"/>
<xsd:complexType name="courseBooking">
<xsd:sequence>
<xsd:element ref="company" />
<xsd:element ref="student" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="courseReference" type="xsd:string" use="required"/>
<xsd:attribute name="courseDate" type="xsd:date" use="required"/>
<xsd:attribute name="invoiceReference" type="xsd:string" use="required"/>
<xsd:attribute name="totalPrice" type="xsd:decimal" use="required"/>
</xsd:complexType>
<xsd:element name="student" type="studentType"/>
<xsd:complexType name="studentType">
<xsd:attribute name="firstName" type="xsd:string" use="required"/>
<xsd:attribute name="surname" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:element name="company" type="companyType"/>
<xsd:complexType name="companyType">
<xsd:sequence>
<xsd:element name="address"/>
<xsd:element ref="contact" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string"/>
</xsd:complexType>
<xsd:element name="contact" type="contactType"/>
<xsd:complexType name="contactType">
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="telephone" type="xsd:string" use="required"/>
<xsd:attribute name="email" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:schema>
run the following command:
$xjc course-booking.xsd -p org.wso2.jaxb.training -d src/generated
● -d <dir>: Place the generated files into this directory.
● -p <package>: Place the generated files in this package.
● -nv: Don't perform strict validation of the input schema.
● -httpproxy <proxy>: Use this if you are behind a proxy. Takes the format [user[:password]@]proxyHost[:proxyPort].
● -classpath <arg>: Specify the classpath, if necessary.
● -readOnly: Generates read-only source code files, if your OS supports this.
There is also an equivalent ant task, which makes it quite easy to integrate into an Ant or Maven-based build process.
@XmlAttribute
For complete reference please visit : https://jaxb.java.net/tutorial/section_6_2_1-A-Survey-Of-
JAXB-Annotations.html#A%20Survey%20Of%20JAXB%20Annotations
JAXB advantages
o It is very simple to use than DOM or SAX
parser
o We can marshal XML file to other data
targets like inputStream,URL,DOM node.
o We can unmarshal XML file from other
data targets.
o We don't need to be aware of XML parsing
techniques.
o We don't need to access XML in tree
structure always.
JAXB disadvantages
o JAXB is high layer API so it has less
control on parsing than SAX or DOM.
o It has some overhead tasks so it is slower
than SAX.
Questions?
❖ https://jaxb.java.net/tutorial/
❖ http://www.mkyong.com/java/jaxb-hello-world-example/
❖ http://javapostsforlearning.blogspot.com/2013/02/jaxb-tutorial.html
Contact us !

More Related Content

What's hot

Ogh Ace Case, Part 1 and 2, Oracle Xml Database, Marco Gralike
Ogh Ace Case, Part 1 and 2, Oracle Xml Database, Marco GralikeOgh Ace Case, Part 1 and 2, Oracle Xml Database, Marco Gralike
Ogh Ace Case, Part 1 and 2, Oracle Xml Database, Marco GralikeMarco Gralike
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming TechniquesRaji Ghawi
 
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...Marco Gralike
 
Advance java session 5
Advance java session 5Advance java session 5
Advance java session 5Smita B Kumar
 
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...Marco Gralike
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJDharita Chokshi
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language Hitesh-Java
 
JDBC Basics (In 20 Minutes Flat)
JDBC Basics (In 20 Minutes Flat)JDBC Basics (In 20 Minutes Flat)
JDBC Basics (In 20 Minutes Flat)Craig Dickson
 
Jdom how it works & how it opened the java process
Jdom how it works & how it opened the java processJdom how it works & how it opened the java process
Jdom how it works & how it opened the java processHicham QAISSI
 
Jdbc presentation
Jdbc presentationJdbc presentation
Jdbc presentationnrjoshiee
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Pooja Talreja
 

What's hot (20)

Ogh Ace Case, Part 1 and 2, Oracle Xml Database, Marco Gralike
Ogh Ace Case, Part 1 and 2, Oracle Xml Database, Marco GralikeOgh Ace Case, Part 1 and 2, Oracle Xml Database, Marco Gralike
Ogh Ace Case, Part 1 and 2, Oracle Xml Database, Marco Gralike
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
 
Xml parsers
Xml parsersXml parsers
Xml parsers
 
Java XML Parsing
Java XML ParsingJava XML Parsing
Java XML Parsing
 
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
Database Access With JDBC
Database Access With JDBCDatabase Access With JDBC
Database Access With JDBC
 
Java full stack1
Java full stack1Java full stack1
Java full stack1
 
Jstl Guide
Jstl GuideJstl Guide
Jstl Guide
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Advance java session 5
Advance java session 5Advance java session 5
Advance java session 5
 
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
XMLDB Building Blocks And Best Practices - Oracle Open World 2008 - Marco Gra...
 
PostgreSQL - Case Study
PostgreSQL - Case StudyPostgreSQL - Case Study
PostgreSQL - Case Study
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
 
java jdbc connection
java jdbc connectionjava jdbc connection
java jdbc connection
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
JDBC Basics (In 20 Minutes Flat)
JDBC Basics (In 20 Minutes Flat)JDBC Basics (In 20 Minutes Flat)
JDBC Basics (In 20 Minutes Flat)
 
Jdom how it works & how it opened the java process
Jdom how it works & how it opened the java processJdom how it works & how it opened the java process
Jdom how it works & how it opened the java process
 
Jdbc presentation
Jdbc presentationJdbc presentation
Jdbc presentation
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
 

Viewers also liked

RESTful services with JAXB and JPA
RESTful services with JAXB and JPARESTful services with JAXB and JPA
RESTful services with JAXB and JPAShaun Smith
 
Ado.net xml data serialization
Ado.net xml data serializationAdo.net xml data serialization
Ado.net xml data serializationRaghu nath
 
SAX, DOM & JDOM parsers for beginners
SAX, DOM & JDOM parsers for beginnersSAX, DOM & JDOM parsers for beginners
SAX, DOM & JDOM parsers for beginnersHicham QAISSI
 
Xml serialization
Xml serializationXml serialization
Xml serializationRaghu nath
 
Serialization in .NET
Serialization in .NETSerialization in .NET
Serialization in .NETAbhi Arya
 
Intro To .Net Threads
Intro To .Net ThreadsIntro To .Net Threads
Intro To .Net Threadsrchakra
 
Xml And JSON Java
Xml And JSON JavaXml And JSON Java
Xml And JSON JavaHenry Addo
 
What are actionable insights? (Introduction to Operational Analytics Software)
What are actionable insights? (Introduction to Operational Analytics Software)What are actionable insights? (Introduction to Operational Analytics Software)
What are actionable insights? (Introduction to Operational Analytics Software)Newton Day Uploads
 
Metricas Ingenieria De Software
Metricas Ingenieria De SoftwareMetricas Ingenieria De Software
Metricas Ingenieria De SoftwareRicardo
 
Metricas de calidad de software
Metricas de calidad de softwareMetricas de calidad de software
Metricas de calidad de softwareisisparada
 

Viewers also liked (16)

RESTful services with JAXB and JPA
RESTful services with JAXB and JPARESTful services with JAXB and JPA
RESTful services with JAXB and JPA
 
Ado.net xml data serialization
Ado.net xml data serializationAdo.net xml data serialization
Ado.net xml data serialization
 
SAX, DOM & JDOM parsers for beginners
SAX, DOM & JDOM parsers for beginnersSAX, DOM & JDOM parsers for beginners
SAX, DOM & JDOM parsers for beginners
 
Xml serialization
Xml serializationXml serialization
Xml serialization
 
Xml & Java
Xml & JavaXml & Java
Xml & Java
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
Xml parsing
Xml parsingXml parsing
Xml parsing
 
Serialization in .NET
Serialization in .NETSerialization in .NET
Serialization in .NET
 
Intro To .Net Threads
Intro To .Net ThreadsIntro To .Net Threads
Intro To .Net Threads
 
Xml And JSON Java
Xml And JSON JavaXml And JSON Java
Xml And JSON Java
 
Threading in C#
Threading in C#Threading in C#
Threading in C#
 
Delegates and events
Delegates and events   Delegates and events
Delegates and events
 
What are actionable insights? (Introduction to Operational Analytics Software)
What are actionable insights? (Introduction to Operational Analytics Software)What are actionable insights? (Introduction to Operational Analytics Software)
What are actionable insights? (Introduction to Operational Analytics Software)
 
Metricas Ingenieria De Software
Metricas Ingenieria De SoftwareMetricas Ingenieria De Software
Metricas Ingenieria De Software
 
JAX B
JAX BJAX B
JAX B
 
Metricas de calidad de software
Metricas de calidad de softwareMetricas de calidad de software
Metricas de calidad de software
 

Similar to XML parsing using jaxb

Ch23 xml processing_with_java
Ch23 xml processing_with_javaCh23 xml processing_with_java
Ch23 xml processing_with_javaardnetij
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
 
Content Storage With Apache Jackrabbit
Content Storage With Apache JackrabbitContent Storage With Apache Jackrabbit
Content Storage With Apache JackrabbitJukka Zitting
 
Java Course 12: XML & XSL, Web & Servlets
Java Course 12: XML & XSL, Web & ServletsJava Course 12: XML & XSL, Web & Servlets
Java Course 12: XML & XSL, Web & ServletsAnton Keks
 
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals WebStackAcademy
 
Attack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and KibanaAttack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and KibanaPrajal Kulkarni
 
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1Marco Gralike
 
Using Stratego/XT for generation of software connectors.
Using Stratego/XT for generation of software connectors.Using Stratego/XT for generation of software connectors.
Using Stratego/XT for generation of software connectors.Michal Malohlava
 
Null Bachaav - May 07 Attack Monitoring workshop.
Null Bachaav - May 07 Attack Monitoring workshop.Null Bachaav - May 07 Attack Monitoring workshop.
Null Bachaav - May 07 Attack Monitoring workshop.Prajal Kulkarni
 
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco GralikeBoost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco GralikeMarco Gralike
 
AngularJS application architecture
AngularJS application architectureAngularJS application architecture
AngularJS application architectureGabriele Falace
 
Introduction To Ant
Introduction To AntIntroduction To Ant
Introduction To AntRajesh Kumar
 
Red Hat Agile integration Workshop Labs
Red Hat Agile integration Workshop LabsRed Hat Agile integration Workshop Labs
Red Hat Agile integration Workshop LabsJudy Breedlove
 

Similar to XML parsing using jaxb (20)

Ch23
Ch23Ch23
Ch23
 
Ch23 xml processing_with_java
Ch23 xml processing_with_javaCh23 xml processing_with_java
Ch23 xml processing_with_java
 
XML
XMLXML
XML
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Extensible markup language attacks
Extensible markup language attacksExtensible markup language attacks
Extensible markup language attacks
 
Content Storage With Apache Jackrabbit
Content Storage With Apache JackrabbitContent Storage With Apache Jackrabbit
Content Storage With Apache Jackrabbit
 
Ajax xml json
Ajax xml jsonAjax xml json
Ajax xml json
 
Java Course 12: XML & XSL, Web & Servlets
Java Course 12: XML & XSL, Web & ServletsJava Course 12: XML & XSL, Web & Servlets
Java Course 12: XML & XSL, Web & Servlets
 
5 xml parsing
5   xml parsing5   xml parsing
5 xml parsing
 
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
 
Attack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and KibanaAttack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and Kibana
 
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1
 
Processing XML
Processing XMLProcessing XML
Processing XML
 
Slickdemo
SlickdemoSlickdemo
Slickdemo
 
Using Stratego/XT for generation of software connectors.
Using Stratego/XT for generation of software connectors.Using Stratego/XT for generation of software connectors.
Using Stratego/XT for generation of software connectors.
 
Null Bachaav - May 07 Attack Monitoring workshop.
Null Bachaav - May 07 Attack Monitoring workshop.Null Bachaav - May 07 Attack Monitoring workshop.
Null Bachaav - May 07 Attack Monitoring workshop.
 
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco GralikeBoost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
 
AngularJS application architecture
AngularJS application architectureAngularJS application architecture
AngularJS application architecture
 
Introduction To Ant
Introduction To AntIntroduction To Ant
Introduction To Ant
 
Red Hat Agile integration Workshop Labs
Red Hat Agile integration Workshop LabsRed Hat Agile integration Workshop Labs
Red Hat Agile integration Workshop Labs
 

Recently uploaded

What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 

Recently uploaded (20)

What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 

XML parsing using jaxb

  • 2.
  • 3. ● Object (DOM, JDOM….etc) ● PUSH (SAX) ● PULL(Stax) ● JAXB(Java Architecture for XML Binding)
  • 4. ● Defines an API for reading and writing Java objects to and from XML documents. ● Don't need to be aware of XML parsing techniques ● No extra dependency needed (its inside JDK) ● Used as a standard in many cases XML JAXB Java Objects
  • 6.
  • 7.
  • 8. JAXB uses annotations to indicate the central elements. Annotation Definition @XmlRootElement(namespace = "namespace") Define the root element for an XML tree @XmlType(propOrder = { "field2", "field1",.. }) Allows to define the order in which the fields are written in the XML file @XmlElement Define the XML element which will be used. @XmlAttribute Define the attribute of an element
  • 10. XML : <?xml version="1.0" encoding="UTF-8"?> <booking xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance"> <company name="ACME Consulting"> <address>10 Coyote Avenue, Arizona, USA</address> <contact name="Duke" email="duke@acme.com" telephone="1234567890"/> </company> <student firstName="Jane" surname="Dow"/> <student firstName="John" surname="Doe"/> </booking> XSD : <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="booking" type="courseBooking"/> <xsd:complexType name="courseBooking"> <xsd:sequence> <xsd:element ref="company" /> <xsd:element ref="student" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> <xsd:attribute name="courseReference" type="xsd:string" use="required"/> <xsd:attribute name="courseDate" type="xsd:date" use="required"/> <xsd:attribute name="invoiceReference" type="xsd:string" use="required"/> <xsd:attribute name="totalPrice" type="xsd:decimal" use="required"/> </xsd:complexType> <xsd:element name="student" type="studentType"/> <xsd:complexType name="studentType"> <xsd:attribute name="firstName" type="xsd:string" use="required"/> <xsd:attribute name="surname" type="xsd:string" use="required"/> </xsd:complexType> <xsd:element name="company" type="companyType"/> <xsd:complexType name="companyType"> <xsd:sequence> <xsd:element name="address"/> <xsd:element ref="contact" /> </xsd:sequence> <xsd:attribute name="name" type="xsd:string"/> </xsd:complexType> <xsd:element name="contact" type="contactType"/> <xsd:complexType name="contactType"> <xsd:attribute name="name" type="xsd:string" use="required"/> <xsd:attribute name="telephone" type="xsd:string" use="required"/> <xsd:attribute name="email" type="xsd:string" use="required"/> </xsd:complexType> </xsd:schema>
  • 11. run the following command: $xjc course-booking.xsd -p org.wso2.jaxb.training -d src/generated ● -d <dir>: Place the generated files into this directory. ● -p <package>: Place the generated files in this package. ● -nv: Don't perform strict validation of the input schema. ● -httpproxy <proxy>: Use this if you are behind a proxy. Takes the format [user[:password]@]proxyHost[:proxyPort]. ● -classpath <arg>: Specify the classpath, if necessary. ● -readOnly: Generates read-only source code files, if your OS supports this. There is also an equivalent ant task, which makes it quite easy to integrate into an Ant or Maven-based build process.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18. @XmlAttribute For complete reference please visit : https://jaxb.java.net/tutorial/section_6_2_1-A-Survey-Of- JAXB-Annotations.html#A%20Survey%20Of%20JAXB%20Annotations
  • 19. JAXB advantages o It is very simple to use than DOM or SAX parser o We can marshal XML file to other data targets like inputStream,URL,DOM node. o We can unmarshal XML file from other data targets. o We don't need to be aware of XML parsing techniques. o We don't need to access XML in tree structure always. JAXB disadvantages o JAXB is high layer API so it has less control on parsing than SAX or DOM. o It has some overhead tasks so it is slower than SAX.
  • 21. ❖ https://jaxb.java.net/tutorial/ ❖ http://www.mkyong.com/java/jaxb-hello-world-example/ ❖ http://javapostsforlearning.blogspot.com/2013/02/jaxb-tutorial.html