parsing java with xml

9
Parsing java with XML

Upload: klaus

Post on 06-Jan-2016

24 views

Category:

Documents


0 download

DESCRIPTION

Parsing java with XML. XML (Extensible Markup language). What is XML? - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Parsing  java with XML

Parsing java with XML

Page 2: Parsing  java with XML

XML (Extensible Markup language) . •What is XML?

•a comprehensive, but difficult superset of HTML to allow you to define and manipulate your own tags. Thus, with HTML you are stuck with its tags but browsers know how to display material (it's all standardized now) whereas with XML you can define your own tags, but you need to provide a "browser" that can interpret the tags and take appropriate action .

Page 3: Parsing  java with XML

Students.XML File<XML version="1.0"> <DOCUMENT> <STUDENT> <NAME> Anorexic Al </NAME> <ADDR> 10 Slimway Rd </ADDR> <GRADE> A </GRADE> </STUDENT> <STUDENT> <NAME> Bulimic Bill </NAME> <ADDR> 123 Upchuck Drive </ADDR> <GRADE> B+ </GRADE> </STUDENT> <STUDENT> <NAME> Cadaverous Chen </NAME> <ADDR> 14 Mordant St. </ADDR> <GRADE> B- </GRADE> </STUDENT> </DOCUMENT>

Page 4: Parsing  java with XML

•You see that this is really a tiny database with three records. This is one current use of XML. Another use is to define tags like <audio></audio> and include actual audio between the tags - this is the idea of creating complex documents. What does a browser do with the above student-database file? Standard HTML browsers will ignore the new tags. Now, it is YOU, the creator of a particular set of tags, that needs to provide a "browser" for the tags you create. Such a browser will parse the file, and extract the content and "do" whatever it is that needs to be done .

Page 5: Parsing  java with XML

These actions might include display in a window, or might have nothing to do with displaying at all (such as placing the database entries above in a regular relational database). How does one write a program to read in an XML file and extract information? Fortunately, this task is made easier by using available tools. One such fundamental tool is an XML parser.

Page 6: Parsing  java with XML

An XML parser in Java allows a Java programmer to include a parser package and write applications to extract data from XML files

(It means "reading" the XML file/string and getting its content according to the structure, usually to use them in a program)

XML Parser

Page 7: Parsing  java with XML

XML Parsing in Java :

Page 8: Parsing  java with XML

A non-validating parser: a parser that does

not detect invalid tags etc.

A validating parser: a parser that checks

syntactic validity.

There are two kinds of parsers

Page 9: Parsing  java with XML

• XML Parser is the abstract base class for the XML parser for Java. An instantiated parser invokes the parse() method to read an XML document.