Parsing XML using DOM Parsing XML using DOM
- Slides: 12
Parsing XML using DOM
Parsing XML using DOM • • Definition: DOM Need of DOM Disadvantages of DOM levels DOM core DOM Traversal and Range Other DOM Implementation JAXB
Definition : DOM • DOM provides a way of representing an XML document in memory so that it can be manipulated by software
Need of DOM • To create and modify an XML document programmatically • Considerable time taken to leverage existing parsers
Disadvantages of DOM • DOM can be memory intensive • DOM is not practical for small devices such as PDAs and cellular phones
DOM levels • Level 1: Traversal of an XML document as well as manipulation of the content in that document • Level 2: Extends level 1 by adding additional features like namepace, events, ranges and so on • Level 3: Currently working draft
DOM Core • package com. docx(Program attached) • C: UserssundariDocumentsNet. Beans. ProjectsDOM XMLsrccombeingjavaguyscoreRead. Xml. java (Program attached) • C: UserssundariDocumentsXMLDOM. xml (Program attached)
DOM Traversal • Node. Iterator—Represents a sub tree of a liner list • Tree. Walker—Represents a subtree view • Node. Filter-Conjunct with above two , to select specific nodes • Document. Traversal-Method to create Node. Iterator and Tree. Walker
DOM Range • Range—Range which contains methods to define delete insert content • Document. Range—Create a range
Other DOM Implementation • • JDOM—API for XML accepted by Java Community Nano. XML-Smaller document (6 KB to 33 KB) Tiny. XML—Reading document k. XML—J 2 ME
JAXB • JAXB, stands for Java Architecture for XML Binding, using JAXB annotation to convert Java object to / from XML file. – Marshalling – Convert a Java object into a XML file. – Unmarshalling – Convert XML content into a Java Object.
EXAMPLE • JAXB-Example. docx(Program attached)