ÈçºÎ ʹÓà java ²Ù×Ý XML Îļþ
Introduction to XML and XML With Java
If you are looking for sample programs to parse a XML file using DOM/SAX parser or looking for a program to generate a XML file please proceed directly to programs.
This small tutorial introduces you to the basic concepts of XML and using Xerces parser for Java to generate and parse XML.
The intended audience are XML beginners with knowledge of Java.
Last updated:
03 Oct 2005.Modified programs runs in JDK 1.3, JDK 1.4 and JDK 1.5. Xerces parser is used with JDK 1.4 and 1.3.
Contents
1 Introduction
2 What is XML
3 Advantages of XML
3.1 Readability
3.2 Hierarchical
3.3 Language Independent
3.4 OS independent
4 Uses of XML
4.1 MetaContent
4.2 Messaging
4.3 Database
5 Parsers
5.1 DOM
5.2 SAX
5.3 When to use DOM Parser
5.4 When to use SAX Parser
5.5 Validating And Non Validating
5.6 Well Formedness
6 Programs
6.1 Parsing and Printing
6.1.1 Using DOM
6.1.2 Using SAX
6.2 Generating XML
7 Instructions to run these programs
7.1 Using JDK 1.5
7.2 Using JDK 1.4
7.3 Using JDK 1.3
Definitions
Introduction:
This is a gentle introduction to XML and using XML with Java. We see what makes XML tick and the advantages of XML . Also we have programs to show how to use Xerces parser for parsing and printing an XML document, to generate XML from arbitrary data.
These programs have been intentionally kept small to get the point across.
Top
2 What is XML ?
Extensible Markup Language
XML is text based markup language.
XML is more than html because html only deal with presentation and carries no information about the data itself.
In HTML
For example
<b>Seagull<b>
<i>3674<i>
<i> 34 </i>
could mean anything
In XML we represent it as.
<Personnel>
<Employee>
<Name>Seagull</Name>
Ïà¹ØÎĵµ£º
Ò»Ìáµ½Ï̺߳ÃÏñÊǼþºÜÂé·³ºÜ¸´ÔÓµÄÊ£¬ÊÂʵÉÏȷʵÈç´Ë£¬Éæ¼°µ½Ï̵߳ıà³ÌÊǺܽ²¾¿¼¼Çɵġ£Õâ¾ÍÐèÒªÎÒÃDZ任˼ά·½Ê½£¬Á˽âÏ̻߳úÖƵıȽÏͨÓõļ¼ÇÉ£¬Ð´³ö¸ßЧµÄ¡¢²»ÒÀÀµÓÚij¸öJVMʵÏֵijÌÐòÀ´¡£±Ï¾¹½ö½ö¾ÍJava¶øÑÔ£¬¸÷¸öÐéÄâ»úµÄʵÏÖÊDz»Í¬µÄ¡£Ñ§Ï°Ïß³Ìʱ£¬×îÁîÎÒÓ¡ÏóÉî¿ÌµÄ¾ÍÊÇÄÇÖÖ²»È·¶¨ÐÔ¡¢Ã»Óб£ÕÏÐÔ£¬¸÷¸öÏ̵߳ÄÔËÐÐÍ ......
ËùÓÐJava
ÐéÄâ»úÖÐʹÓõÄÊý¾Ý¶¼ÓÐÈ·¶¨µÄÊý¾ÝÀàÐÍ£¬Êý¾ÝÀàÐͺͲÙ×÷¶¼ÔÚJava
ÐéÄâ»ú¹æ·¶ÖÐÑϸñ¶¨Òå¡£Java
ÖеÄÊý¾ÝÀàÐÍ·ÖΪÔʼÊý¾ÝÀàÐÍ £¨primitive types
£©ºÍÒýÓÃÊý¾ÝÀàÐÍ£¨reference type
£©¡£ÒýÓÃÀàÐÍÒÀÀµÓÚʵ¼ÊµÄ¶ÔÏ󣬵«²»ÊǶÔÏó±¾Éí¡£ÔʼÊý¾ÝÀàÐͲ»ÒÀÀµÓÚÈκζ«Î÷£¬ËüÃǾÍÊDZ¾Éí±íʾµÄÊ ......
Java
ÐéÄâ»úÖеÄÀà¼ÓÔØÆ÷·ÖΪÁ½ÖÖ£ºÔʼÀà¼ÓÔØÆ÷£¨primordial class loader
£©ºÍÀà¼ÓÔØÆ÷¶ÔÏó£¨class loader objects
£©¡£
ÔʼÀà¼ÓÔØÆ÷ÊÇJava
ÐéÄâ»úʵÏÖµÄÒ»²¿·Ö£¬Àà¼ÓÔØÆ÷¶ÔÏóÊÇÔËÐÐÖеijÌÐòµÄÒ»²¿·Ö¡£²»Í¬Àà¼ÓÔØÆ÷¼ÓÔصÄÀà±»²»Í¬µÄÃüÃû¿Õ¼äËù·Ö¸î¡£
Àà¼ÓÔØÆ÷µ÷ÓÃÁËÐí¶àJava ......
¼×¹ÇÎÄÒѾÍê³ÉÁ˶ÔSUN¹«Ë¾µÄÊÕ¹º£¬ÓÚ1ÔÂ27ÈÕ·¢²¼Á˶ÔSun¸÷ÏîÒµÎñµÄÕûºÏ¹æ»®¡£×ÜÌåÉÏ˵£¬OracleÒª³ÉΪÈíÓ²¼þÒ»Ì廯µÄÕûÌå½â¾ö·½°¸µÄ³§ÉÌ¡£ ÒÔϾÍÆä¶Ô±¸ÊܹØ×¢µÄJava·½ÃæµÄ²ßÂÔ×ö¸ö½éÉÜ¡£
Java SE:
1£©ÍƳöJDK SE 7£¬ Ëü½«°üÀ¨¶à¸öÐµĹ¦ÄÜ£¬ÈçÌá¸ß¿ª·¢ÈËÔ±µÄЧÂÊ£¬Ìṩ¸ßÐÔÄÜ£¬¶Ô¶àºËоƬµÄÖ§³ÖµÈ¡£
2£©SunµÄHotSpot ......