Skip to Content

TheBlogReaders.com

Salesforce.com, PHP, MySQL, Javascript, Ajax, Htacces

Java XML Interview Questions and Answers For Freshers Part-3

Be First!

java xml21.What is JDOM Parser?
JDOM is an open source, java based library to parse XML document and it is typically java developer friendly API.

22.What are the benefits of JDOM parser?
It is java optimized, it uses java collection like List and Arrays. It works with DOM and SAX APIs and combines the best of the two. It is of low memory footprint and is nearly as fast as SAX.

23.When to use a JDOM Parser?
You should use a JDOM parser when −

You need to know a lot about the structure of a document.

You need to move parts of the document around (you might want to sort certain elements, for example).

You need to use the information in the document more than once.

You are a java developer and want to leverage java optimized parsing of XML.

24.What are the advantages of JDOM parser?
When you parse an XML document with a JDOM parser, you get the flexibility to get back a tree structure that contains all of the elements of your document without impacting the memory footprint of the application. The JDOM provides a variety of utility functions you can use to examine the contents and structure of the document in case document is well structured and its structure is known.

25.Name some of the important JDOM classes.?

The JDOM defines several Java classes. Here are the most common classes −

Document – Represents the entire XML document. A Document object is often referred to as a DOM tree.

Element – Represents an XML element. Element object has methods to manipulate its child elements,its text, attributes and namespaces.

Attribute Represents an attribute of an element. Attribute has method to get and set the value of attribute. It has parent and attribute type.

Text Represents the text of XML tag.

Comment Represents the comments in a XML document.

26.Name some of the important JDOM methods.
When you are working with the JDOM, there are several methods you’ll use often −

SAXBuilder.build(xmlSource) – Build the JDOM document from the xml source.

Document.getRootElement() – Get the root element of the XML.

Element.getName() – Get the name of the XML node.

Element.getChildren() – Get all the direct child nodes of an element.

Node.getChildren(Name) – Get all the direct child nodes with a given name.

Node.getChild(Name) – Get first child node with given name.

27.Can we create an XML document using JDOM parser?
Yes! Using JDOM parser, we can parse, modify and create a XML document.

28.What is a StAX Parser?
StAX is a JAVA based API to parse XML document in a similar way as SAX parser does but StAX is a PULL API where as SAX is a PUSH API. It means in case of StAX parser, client application need to ask StAX parser to get information from XML whenever it needs but in case of SAX parser, client application is required to get information when SAX parser notifies the client application that information is available.

29.Can we create an XML document using StAX parser?
Yes! Using StAX parser, we can parse, modify and create a XML document.

30.Is StAX parser a PULL API?
Yes! StAX is a PULL API.

(174)

Previous
Next

Leave a Reply