1 / 9

Parsing java with XML

Parsing java with XML. XML (Extensible Markup language). What is XML?

klaus
Télécharger la présentation

Parsing java with XML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Parsing java with XML

  2. 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.

  3. 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>

  4. 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.

  5. 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.

  6. 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)

  7. XML Parsing in Java:

  8. 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

  9. 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.

More Related