Tuesday, December 5, 2017

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

No comments:

Post a Comment