Loading
XML-Java Interview Questions

Java Quick Notes

Refresh Your Java

We are Agile, believe in less Documentation - Only Quick notes of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

"Click on other Tabs for more Questions"  

"XML-Java "


XML-Java

1 )   What is xml ?


Ans)

Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding
documents in a format that is both human-readable and machine-readable.

Example XML :

<Customer>
<FirstName>Smith</FirstName>
<LastName>Robert</LastName>>
</Customer>



Back to top

2 )   What is the XML Element and Attribute ?


Ans)

An element describes the data that it contains. Elements can also contain other elements and
attributes. For more information, see below.

Element :
<xs:element name="quantity" type="xs:integer" />
XML  :
<quantity>63</quantity>

An attribute is a named simple-type definition that cannot contain other elements. Attributes can
also be assigned an optional default value and they must appear at the bottom of complex-type
definitions.

Exmaple Attribute :
<xs:element name="OrderInfo">
<xs:complexType>
<xs:attribute name="OrderDiscount" type="xs:number" />
</xs:complexType>
</xs:element>

XML :
<OrderInfo number='123456'> </OrderInfo>



Back to top

3 )   What is DTD ?


Ans)

DTD stands for "Document Type Definitions are the Basis of Markup Languages", which provides
a list of the elements, attributes, comments, notes, and entities contained in the document.

It also indicates their relationship to one another within the document. In other words, a DTD
is the grammar of an XML or HTML document.  Please the example below.
 

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- the XHTML document body starts here-->
<html>
 ...
</html>



Back to top

4 )   What is CDATA ?


Ans)

CDATA stands for Character Data and it means that the data in between these tags includes
data that should not be interpreted as XML.

So the term CDATA is used about text data that should not be parsed by the XML parser.
 

Take a look at sample below :
<![CDATA[
<Test>This is a Test</Test>]]>

 



Back to top

5 )   What is XSD ?


Ans)

XML Schema Definition (XSD) language is the current standard schema language for all XML
documents and data. The XML Schema definition (XSD) enables you to define the structure
and data types for XML documents.
An XML Schema defines the elements, attributes, and data types
that conform to the World Wide Web Consortium (W3C) XML Schema

The elements of Scheme possibly have two kinds of Types to define data, Simpletype,complextype.

Example :
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="urn:books"
            xmlns:bks="urn:books">
  <xsd:element name="books" type="bks:BooksForm"/>
  <xsd:complexType name="BooksForm">
    <xsd:sequence>
      <xsd:element name="book"
                  type="bks:BookForm"
                  minOccurs="0"
                  maxOccurs="unbounded"/>
      </xsd:sequence>
  </xsd:complexType>
</xsd:schema>



Back to top

6 )   DTD VS XSD ?


Ans)

Both Document Type Definitions (DTD's) and XML Schemas (XSD's, also known as WXS)
are industry-standard ways to define XML-based data models, and you'll find many tools
and utilities for working with both DTD and XML Schema in Stylus Studio/XML Spy.

 

DTD XSD
  Support for primitive (built-in) data types (eg: xsd:integer, xsd:string, xsd:date, and so on), which facilitates using XML in conjunction with other typed-data, including relational data.
  The ability to define custom data types, using object-oriented data modeling principles: encapsulation, inheritance, and substitution.
Compatibility other XML technologies, for example, Web services, XQuery, XSLT and other technologies can optionally be schema-aware.
 

Better Performamce

you must also consider the fact that the XML Schema is an XML document. It has an XML Namespace to refer to, and an XML DTD to define it. This is all overhead. When a parser examines the document, it may have to link this all in, interperate the DTD for the Schema, load the namespace, and validate the schema, etc., all before it can parse the actual XML document in question. If you’re using XML as a protocol between two systems that are in heavy use, and need a quick response, then this overhead may seriously degrade performance

 

 



Back to top

7 )   What is the Prolog ?


Ans)

The prolog is an optional component of the XML document. If included, the prolog must
be appear before the root element as shown below.

It looks like this

<?xml version="1.0" encoding="UTF-8" ?>



Back to top

8 )    What is Target Name Space ?


Ans)

The names defined in a schema are said to belong to its target namespace.
You can use the xsd:targetNamespace attribute to place elements and attributes from the
default namespace into a different namespace.

<xsd:schema targetNamespace='http://www.SampleStore.com/Account'
      xmlns:xsd='http://www.w3.org/1999/XMLSchema'
      xmlns:ACC= 'http://www.SampleStore.com/Account'>
<xsd:element name='InvoiceNo' type='xsd:positive-integer'/>
<xsd:element name='ProductID' type='ACC:ProductCode'/>
<xsd:simpleType name='ProductCode' base='xsd:string'>
  <xsd:pattern value='[A-Z]{1}d{6}'/>
</xsd:simpleType>     

In Above example

             "ProductID (ACC:ProductCode)" is in  "'http://www.SampleStore.com/Account"
             
"xsd:element" in in "http://www.w3.org/1999/XMLSchema"



Back to top

9 )   What are the Default Data Types in XSD ?


Ans)

Types in XML Schema can be Simple or Complex.
Simple Types :
There are two major categories of simple types:
 a)Build In types:  Which are defined by the World Wide Web Consortium's XML Schema
   specification - for example, string, boolean, decimal, double,dateTime and float etc.,
 b) User-defined simple types: Imple types are derived from the W3C built-in types by
   applying user-defined values to items called facets

Complex Types:
Complex types are element definitions that can include other elements, attributes, and groups.
simple types cannot include other elements, attributes, or groups but can only include facets,
but we could include all of these in Complex Types.



Back to top

10 )   What is SAX parser ?


Ans)

The SAX specification defines an event-based approach whereby parsers scan through XML data,
calling handler functions whenever certain parts of the document (e.g., text nodes or processing
instructions) are found.

These events include the start and end of the document, finding a text node, finding child elements,
and hitting a malformed element. So the SAX parser doesn't create any internal representation of the
document. Instead, the parser calls handler functions when certain events
defined by the SAX specification) take place.

Here is the Example of Java Sax Parser:


public class Test extends DefaultHandler  {
        public static void main(String[] args) {
                try {
                        Test saxNames = new Test();
                        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
                        parser.parse(new File("C://document.xml"),saxNames);
                } catch (Exception e) {
                        e.printStackTrace(System.err);
                }
        }
        public void startElement(String uri, String localName, String qName,
                        Attributes attrs) {
          }
        public void endElement(String uri, String localName, String qName) {
        }
 }



Back to top

11 )   What is DOM parser ?


Ans)

The DOM specification defines a tree-based approach to navigating an XML document. In other
words, a DOM parser processes XML data and creates an object-oriented hierarchical representation
of the document that you can navigate at run-time.

public class Test {
        public static void main(String[] args) {
                try {
                        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();    
                        DocumentBuilder db = dbf.newDocumentBuilder();        
                        InputSource is = new InputSource(new StringReader(in));
                        return db.parse(is);     

                } catch (Exception e) {
               }
        }
}



Back to top

12 )   SAX VS DOM ?


Ans)

The SAX parser doesn't create any internal representation of the document, so it can scan
and parse gigabytes worth of XML documents without hitting resource limits because it does
not try to create the DOM representation in memory. Instead, it raises events that you can
handle as you see fit. Because of this design, the SAX implementation is generally faster
and requires fewer resources.

On the other hand, SAX code is frequently complex, and the lack of a document representation
leaves you with the challenge of manipulating, serializing, and traversing the XML document.

With SAX parser you could not traverse back once an elemented is processed, but with DOM
you can traverse through back and froth.



Back to top

13 )   What is XSLT ?


Ans)

Extensible Stylesheet Language Transformations (XSLT) has evolved from the early Extensible
Stylesheet Language (XSL) standard. XSL specifies a language definition for XML data presentation
and data transformations.

Here is the eaxmple of helloworld xslt.
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="hello.xsl"?>
<hello-world>
<greeter>An XSLT Programmer</greeter> <greeting>Hello, World!</greeting>
</hello-world>

XSLT :

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
 <xsl:template match="/hello-world">
 <HTML> <HEAD> <TITLE></TITLE> </HEAD> <BODY> <H1>
 <xsl:value-of select="greeting"/> </H1> <xsl:apply-templates select="greeter"/>
 </BODY> </HTML> </xsl:template> <xsl:template match="greeter">
 <DIV>from <I><xsl:value-of select="."/></I></DIV>
 </xsl:template> </xsl:stylesheet>



Back to top

14 )   XML Binding ?


Ans)

Databinding is a general concept that is regularly applied even outside the context of
Web services, but  in the context of Web services, databinding is always XML databinding.
XML databinding is nothing but a process which maps the content of an XML document to a
set of objects generated specifically to provide access to data contained in those documents.

This could be done by using several APIs , some of them are below.

i) JaxB
ii) Castor
iii) Xstream
iv) JBix



Back to top

15 )   XSD to Java ?


Ans)


  • XSD to Java ?
    Sample Img 15

XSD to Java , there are several ways to do this.

 

JAXB:
The JAXB binding compiler translates a W3C XML Schema into one or more Java classes,
a jaxb.properties file, and possibly other files, depending on the specific implementation
of JAXB. Alternatively, JAXB2 offers a way to generate a schema from annotated Java classes.

Below is the call to generate the JAXB classes from an XML schema:
 xjc -d out Example.xsd 


XMLBeans:
XMLBeans is an XML binding tool that has full XML Schema support, and offers full XML Infoset
fidelity. It takes a different approach to that of most other O/X mapping frameworks,
in that all classes that are generated from an XML Schema are all derived from XmlObject,
and contain XML binding information in them.

Below is the call to generate the JAXB classes from an XML schema:
 scomp -d out -srconly  Example.xsd

With XML SPY :

You can use some tools like XML Spy to do this, please take a look at above Image.

 



Back to top

16 )   What Is XPath ?


Ans)

XPath is a language for addressing parts of an XML document,
designed to be used by both XSLT and XPointer.

Assume that you have a XML file named "books.xml"

doc( "books.xml")/bookstore/book(price>30)/title

 



Back to top

17 )   What is XQuery ?


Ans)

Assume that you have a XML file named "books.xml"

 

for $x in doc ("books.xml")/bookstore/book

where $x/price>30

return $x/title

 



Back to top

Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,

This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.




Face Book

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free

Go To Site Map