¶àÖÖXML½âÎö·½·¨
±¾ÎĽéÉÜÁ˸÷ÖÖ½âÎö·½·¨£¬×ÅÖØ·ÖÎöÁ˸÷×ÔµÄÓÅȱµã:
½âÎöµÄÖØÒªÐÔ
¡¡¡¡½âÎöΪʲôÖØÒª?ÒòΪËùÓÐ XML ´¦Àí¶¼´Ó½âÎö¿ªÊ¼¡£ÎÞÂÛʹÓø߲ã±à³ÌÓïÑÔ(Èç XSLT)»¹ÊǵͲã Java ±à³Ì£¬µÚÒ»²½¶¼ÊÇÒª¶ÁÈë XML Îļþ£¬½âÂë½á¹¹ºÍ¼ìË÷ÐÅÏ¢µÈµÈ£¬Õâ¾ÍÊǽâÎö¡£
¡¡¡¡½âÎöÎĵµÊ±ÃæÁٵĵÚÒ»¸öÑ¡ÔñÊDzÉÓÃÏֳɵĽâÎö¿â(»ù±¾ÉÏÿÖÖ±à³ÌÓïÑÔ¶¼ÓУ¬°üÀ¨ COBOL [Common Business Oriented Language])»¹ÊÇ×Ô¼º´´½¨Ò»¸ö¡£´ð°¸·Ç³£¼òµ¥£ºÑ¡ÔñÏֳɵĿ⡣
¡¡¡¡Ì¹°×µØ˵£¬XML ²»ÊÇÒ»ÖÖ¶àô¸´ÔÓµÄÓï·¨£¬Òò´ËÈÏΪ¿ÉÒÔ×Ô¼ºÍ¨¹ýÕýÔò±í´ïʽ»òÆäËûÌØÊâ·½·¨À´½âÎöµÄÏë·¨ÊÇ¿ÉÒÔÀí½âµÄ¡£µ«Êµ¼ÊÉÏÈ´ºÜÄѳɹ¦£ºXML Óï·¨ÒªÇóÖ§³Ö¶àÖÖ±àÂëºÍºÜ¶àÄÑÒÔ×½ÃþµÄÌØÐÔ£¬±ÈÈç CDATA ½ÚºÍʵÌå¡£×Ô¶¨ÒåµÄʵÏÖ¼¸ºõºÜÄÑÕչ˵½ËùÓÐÕâЩ·½Ã棬Òò¶øÔì³ÉÁ˲»¼æÈÝÐÔ¡£
¡¡¡¡Ïà·´£¬Ë濪·¢»·¾³ÌṩµÄ½âÎöÆ÷´ó¶¼¾¹ýÁËÓë¼æÈÝÐÔÓйصIJâÊÔ¡£²ÉÓà XML ÕâÑùµÄ±ê×¼Óï·¨µÄÖ÷ÒªÔÒòÊǼæÈÝÆäËûÓ¦ÓóÌÐòºÍ¹¤¾ßÏ䣬ÕâÊÇÕæÕýÖµµÃʹÓþ¹ýÁ¼ºÃ²âÊԵĿâµÄÇé¿öÖ®Ò»¡£
¡¡¡¡¶àÊý½âÎöÆ÷ÌṩÁËÖÁÉÙÁ½ÖÖ API£¬Í¨³£ÊÇÒ»¸ö¶ÔÏóÄ£ÐÍ API ºÍÒ»¸öʼþ API(Ò²³ÆΪÁ÷ API)¡£±ÈÈ磬Java ƽ̨ͬʱÌṩÁË DOM(Îĵµ¶ÔÏóÄ£ÐÍ)ºÍ SAX(Simple API for XML)¡£
¡¡¡¡ÕâÁ½Ì× API ÌṩÁËÏàͬµÄ·þÎñ£ºÎĵµ½âÂë¡¢¿ÉÑ¡µÄÑéÖ¤¡¢Ãû³Æ¿Õ¼ä½âÎöµÈµÈ¡£²î±ð²»ÔÚÓÚ·þÎñ¶øÔÚÓÚ API ʹÓõÄÊý¾ÝÄ£ÐÍ¡£
¡¡¡¡¹Ø¼üµÄÑ¡Ôñ£ºµÚÒ»ÖÖ·½·¨
¡¡¡¡¶ÔÏóÄ£ÐÍ API ¶¨ÒåÁ˲ã´Î»¯¶ÔÏóÄ£ÐÍÀ´±íʾ XML Îĵµ¡£»»¾ä»°Ëµ£¬¶ÔÓ¦ XML Óï·¨ÖеÄÿ¸ö¸ÅÄÒåÏàÓ¦µÄÀࣺԪËØ¡¢ÊôÐÔ¡¢ÊµÌå¡¢Îĵµ¡£½âÎöÆ÷¶ÁÈë XML ÎĵµµÄʱºò£¬½¨Á¢ XML Óï·¨ºÍÀàÖ®¼äµÄÒ»¶ÔÒ»Ó³Éä¡£±ÈÈ磬ÿÓöµ½Ò»¸ö±ê¼Ç£¬¾ÍʵÀý»¯Ò»¸öÔªËØÀà¡£
¡¡¡¡ºÁ²»Ææ¹Ö£¬¶ÔÄÄÖÖÊý¾ÝÄ£ÐÍ×îºÃ´æÔÚһЩÕùÒé¡£W3C ¹æ·¶»¯ÁË DOM£¬ËüµÄÖ÷ÒªÓŵãÊÇ¿ÉÒÆÖ²ÐÔ£ºËüÊÇ×÷ΪһÖÖ CORBA ½Ó¿Ú¶¨ÒåµÄ£¬±»Ó³Éäµ½ºÜ¶àÓïÑÔ¡£Òò´ËÈç¹ûÁ˽âÁË JavaScript ÖÐµÄ DOM£¬Ò²¾ÍÖªµÀÁË Java¡¢C++¡¢Perl¡¢Python ºÍÆäËûÓïÑÔÖÐµÄ DOM¡£
¡¡¡¡ÁíÒ»ÖÖÊý¾ÝÄ£ÐÍÊÇ JDOM£¬Ò»ÖÖÕë¶Ô Java ÓÅ»¯µÄ DOM(רÓÃÓÚ Java)£¬ºÍ Java ÓïÑÔ½áºÏµÃ¸ü½ôÃÜ£¬µ«ÊÇ°´ÕÕ¶¨Òåȱ·¦¿ÉÒÆÖ²ÐÔ¡£
¡¡¡¡¾¡¹ÜÈËÃÇ¿ÉÒÔ¼ÌÐøÉÌÌÖ¶Ô XML Óï·¨À´ËµÄÄÖÖÊý¾ÝÄ£ÐÍ×îºÃ£¬µ«ÎÒÈÏΪûÓжàÉÙÒâÒ壬ÒòΪ¸÷ÖÖ»ùÓÚ¶ÔÏóµÄ API ÆäÓŵãºÍ²»×ã»ù±¾ÉÏÊÇÒ»ÑùµÄ¡£´ÓºÃµÄ·½ÃæÀ´Ëµ£¬Èç¹ûÊìϤ XML Óï·¨µÄ»°£¬¶ÔÏóÄ£ÐÍ API ¸üÈÝÒ×Àí½â¡£ÒòΪËüÖ±½Ó´Ó XML Óï·¨Ó³Éäµ½À࣬ºÜÈÝÒ×ѧϰ¡¢Ê¹Óú͵÷ÊÔ¡£
¡¡¡¡¼òµ¥µÄ´ú¼ÛÊÇЧÂÊ£¬ÖÁ
Ïà¹ØÎĵµ£º
SQl XmlºÍC# XmlÊý¾ÝµÄÒ»µã²Ù×÷×ܽá
ÔÚ´ËÉêÃ÷XmlÊÇInfoSetÊý¾Ý²»ÊÇ×Ö·û´®£¬ËùÒÔÔÚ´ËÇ¿ÁÒ·´¶ÔÓÃstringÆ´½Óxml¡£Êý¾Ý¿â¿ÉÒÔ´æ·ÅxmlÀàÐÍÊý¾Ý£¬ÄÇô¸ÃÊý¾ÝµÄ¾ßÌå²Ù×÷ÓÖÈçºÎÁË¡£
1.Ê×ÏȽ¨Á¢Ò»Õź¬ÓÐxmlÊý¾ÝÀàÐ͵ıí
CREATE TABLE [dbo].[TestXml](
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[Message] [xml] NULL ......
´úÂëÈçÏÂ:
DECLARE
@TempTable table(UserID int , UserName nvarchar(50));
insert into
@TempTable (UserID,UserName) values (1,'a')
insert into @TempTable
(UserID,UserName) values (2,'b')
select UserID,UserName
from @TempTable FOR XML PATH
ÔËÐÐÕâ¶Î½Å±¾£¬½«Éú³ÉÈçϽá¹û£º
¸´ÖÆ´úÂë
......
ÒÑÖªÓÐÒ»¸öXMLÎļþ£¨bookstore.xml£©ÈçÏ£º
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
&nb ......
ͨ¹ýµ÷ÓÃCreateDataSetfromXmlÈ¡µÃXMLÊý¾Ý
Imports System.Xml
Public Const FILE_CONFIG = "MZZ.xml"
Public Const PATH_CONFIG = "\XML\"
Dim dstXML As DataSet
Dim tblXML_DB As DataTable
Dim dtCod As New DataTable
Dim strSQL As String = ""
clsPublic ......
ÕâÊÇÒ»¸öÓÃJAVA W3C DOM ½øÐÐXML²Ù×÷µÄÀý×Ó£¬°üº¬Á˲éѯ¡¢Ôö¼Ó¡¢Ð޸ġ¢É¾³ý¡¢±£´æµÄ»ù±¾²Ù×÷¡£½ÏÍêÕûµÄÃèÊöÁËÒ»¸öXMLµÄÕû¸ö²Ù×÷Á÷³Ì¡£ÊʺϸÕÈëÃÅJAVA XML²Ù×÷µÄÅóÓѲο¼ºÍѧϰ¡£
¼ÙÉèÓÐXMLÎļþ£ºtest1.xml
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book>
<name>¹þÀï²¨Ì ......