90 likes | 209 Vues
Parsing java with XML . XML (Extensible Markup language) . . What is XML?
E N D
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.
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>
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.
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.
XML Parser 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)
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
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.