Skip to main content

12. J2EE: JAXB


Basics!

Q1: What is Xml ?

Data wrapped in tags.

Q2: How  is it different from HTML ?

XML and HTML were designed with different goals:
  • XML was designed to carry data - with focus on what data is
  • HTML was designed to display data - with focus on how data looks
  • XML tags are not predefined like HTML tags are
Q3: Why do we need them ? 
  •  Data sharing
  • Data transport
  • Cross platform data exchange and interaction 
Q4: What is prolog ?

A prolog defines the XML version and the character encoding:
<?xml version="1.0" encoding="UTF-8"?>

Q5: Why are the 7 rules of well-formed XML document ?
  1.  Every starting and end tag
  2. Attributes values should be in quotes
  3. Entity References: Greater ,lesser etc signs must be specified in '<' this way ,parser won't understand them          <message>salary < 1000</message>
  4. Proper nesting of elements
  5. Elements are case sensitive
  6. Doesn't truncate multiple white spaces

Q6: Element can contain
  1. text
  2. attributes
  3. other elements
  4. or a mix of the above
Q7: Attribute Rules

Specify in single or double quotes

Q8: Element vs Attribute

Some things to consider when using attributes are:
  • attributes cannot contain multiple values (elements can)
  • attributes cannot contain tree structures (elements can)
  • attributes are not easily expandable (for future changes)
THUMB RULE: Choose attribute for atomic value

Q8: What is xmlns attribute for ?

This XML carries HTML table information: TO avoid namespace conflicts you can specify 
<table xmlns="http://www.w3.org/TR/html4/">
  <tr>
    <td>Apples</td>
    <td>Bananas</td>
  </tr>
</table>
This XML carries information about a piece of furniture:
<table xmlns="https://www.w3schools.com/furniture">
  <name>African Coffee Table</name>
  <width>80</width>
  <length>120</length>
</table>


Q9: What is xmlns attribute for ?



Q9: Why is XMLHttpRequest object so important ?

The XMLHttpRequest object can be used to request data from a web server.
The XMLHttpRequest object is a developers dream, because you can:
  • Update a web page without reloading the page
  • Request data from a server - after the page has loaded
  • Receive data from a server  - after the page has loaded
  • Send data to a server - in the background

Q10: What is DOM?What are various types?

The DOM defines a standard for accessing and manipulating documents:

HTML DOM


<h1 id="demo">This is a Heading</h1>

<button type="button"
onclick="document.getElementById('demo').innerHTML = 'Hello World!'"
>
Click Me!
</button>

XML DOM


txt = xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;

Q11: Why is XPath ?

Navigate mechanism to access element either based on some attribute or criteria
  • XPath is a syntax for defining parts of an XML document
  • XPath uses path expressions to navigate in XML documents
  • XPath contains a library of standard functions
  • XPath is a major element in XSLT and in XQuery

Q12: Why is XSLT(Extensible stylesheet ?

Mechanism to transform XML to HTML

XSLT uses XPath to find information in an XML document.

Q12: Why is XQuery ?

XQuery is to XML what SQL is to databases.
XQuery was designed to query XML data.

Q14: Why is XLink?

XLink is used to create hyperlinks in XML documents.

<h xmlns:xlink="http://www.w3.org/1999/xlink">
  <ho xlink:type="simple" xlink:href="https://www.w3schools.com">Visit W3Schools</hom>
  <ho xlink:type="simple" xlink:href="http://www.w3.org">Visit W3C</ho>
</h>
xmlns:xlink
xlink:type
xlink:href


Q15: What is DTD?How many types of DTDs are there ?


There are two different document type definitions that can be used with XML:
  • DTD - The original Document Type Definition
  • XML Schema - An XML-based alternative to DTD
A document type definition defines the rules and the legal elements and attributes for an XML document.

Q16: What is DTD?How many types of DTDs are there ?

  • xml DTD 

  • DTD


Q17: What is XML schema?

XML Schema is an XML-based alternative to DTD:

<xs:element name="note">

<xs:complexType>
  <xs:sequence>
    <xs:element name="to" type="xs:string"/>
    <xs:element name="from" type="xs:string"/>
    <xs:element name="heading" type="xs:string"/>
    <xs:element name="body" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

</xs:element>

Q17: What's the difference between ?



Q:What is JAXB needed for ?

For converting XML TO Java Object & vice versa


JAXB vs DOM and SAX

https://stackoverflow.com/questions/7709928/jaxb-vs-dom-and-sax



________________________________________________________







Download complete example from

https://github.com/vidz2015/tommyhilfiger/tree/master/JAXB

Comments

Popular posts from this blog

Microservices Design patterns

What are microservices? Microservices - also known as the microservice architecture - is an architectural style that structures an application as a collection of services that are Highly maintainable and testable Loosely coupled Independently deployable Organized around business capabilities Owned by a small team The microservice architecture enables the rapid, frequent and reliable delivery of large, complex applications. It also enables an organization to evolve its technology stack. You are developing a server-side enterprise application. It must support a variety of different clients including desktop browsers, mobile browsers and native mobile applications. The application might also expose an API for 3rd parties to consume. It might also integrate with other applications via either web services or a message broker. The application handles requests (HTTP requests and messages) by executing business logic; accessing a database; exchanging messages with other systems; and returni...

GraphQL

What is GraphQL  API Standard invented & open-sourced by Facebook Alternative to  REST API  enables declarative data fetching  exposes single endpoint & responds to queries How it works?  Why Graphql? Improvises performance by reducing the data that is to be transferred over the internet Variety of different frontend frameworks and platforms on client-side Fast development speed & expectation for rapid feature development Why Graphql is better than REST? Flexibility & efficient  No more over /under fetching of data Over fetching : Under fetching: Insightful analytics  Schema serves as contract between client and server CORE CONCEPTS : SDL :SCHEMA DEFINITION LANGUAGE Writing Data with mutations 3 kinds of mutations creating new data updating existing data deleting existing data

Jackson

<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId> jackson-core </artifactId> <version>2.9.6</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId> jackson-annotations </artifactId> <version>2.9.6</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId> jackson-databind </artifactId> <version>2.9.6</version> </dependency> CBOR encoded data with Jackson <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-cbor</artifactId> <version>2.9.6</version> </dependency> In order to read and write MessagePack encoded data <dependency> <groupId>org.msgpack</groupId> <artifactId>jackson-dataformat-msgp...