¹ØÓÚSQLServer2005µÄѧϰ±Ê¼Ç——XMLµÄ´¦Àí
ÔÚ
SQLServer2005
ÖжÔ
XML
µÄ´¦Àí¹¦ÄÜÏÔÈ»ÔöÇ¿Á˺ܶ࣬ÌṩÁË
query(),value(),exist(),modify(),nodes()
µÈº¯Êý¡£
¹ØÓÚ
xml
£¬ÄÑÒÔÀí½âµÄ²»ÊÇ
SQLServer
ÌṩµÄº¯Êý£¬¶øÊǶÔ
xml
±¾ÉíµÄÀí½â£¬¿´Ëƺܼòµ¥µÄÎļþ¸ñʽ£¬´¦ÀíÆðÀ´È´ÊǷdz£À§Äѵġ£±¾ÎÄÖ»Êdzõ̽һ϶øÒÑ¡£
Ïê¼û
SQLServer
Áª»ú°ïÖú£º
Ö÷Ìâ
˵Ã÷
query()
·½·¨£¨
xml
Êý¾ÝÀàÐÍ£©
´Ë·½·¨ÓÃÓÚ¶Ô
XML
ʵÀý½øÐвéѯ¡£
value()
·½·¨£¨
xml
Êý¾ÝÀàÐÍ£©
´Ë·½·¨ÓÃÓÚ´Ó
XML
ʵÀý¼ìË÷
SQL
ÀàÐ͵ÄÖµ¡£
exist()
·½·¨£¨
xml
Êý¾ÝÀàÐÍ£©
´Ë·½·¨ÓÃÓÚÈ·¶¨²éѯÊÇ·ñ·µ»Ø·Ç¿Õ½á¹û¡£
modify()
·½·¨£¨
xml
Êý¾ÝÀàÐÍ£©
´Ë·½·¨ÓÃÓÚÖ¸¶¨
XML DML
Óï¾äÒÔÖ´ÐиüС£
nodes()
·½·¨£¨
xml
Êý¾ÝÀàÐÍ£©
´Ë·½·¨ÓÃÓÚ½«
XML
²ð·Ö³É¶àÐÐÒÔ½«
XML
ÎĵµµÄ×é³É²¿·Ö´«²¥µ½Ðм¯ÖС£
Ïл°ÉÙ˵£¬Ê×ÏÈ´´½¨Ò»¸ö°üº¬
xml
ÀàÐ͵ÄÊý¾Ý±í£¬Æä´Î´´½¨Ò»¸ö
xml
Îļþ£¬ÔÚ·þÎñ¶Ë°Ñ
xml
ÎļþÄÚÈݼÓÔظÃÊý¾Ý±íÖС£
CREATE TABLE VisioXML
(
ID
INT,
Doc
XML
);
GO
´´½¨Ò»¸öÃûΪ
xxx.xml
µÄÎļþ£¬ÄÚÈÝÈçÏÂ
/*
<ROOT>
<ROW>
<ID>1</ID>
<NAME SEX="MALE">WBQ</NAME>
</ROW>
<ROW>
<ID>2</ID>
<NAME SEX="FEMALE">CZH</NAME>
</ROW>
</ROOT>
*/
INSERT INTO VisioXML(ID,Doc)
SELECT 4,* from OPENROWSET(BULK
'e:\xxx.xml',SINGLE_BLOB) AS x;
--
ÒÔÏÂΪ
value()
ºÍ
query()
µÄÓ÷¨
--SELECT * from VisioXML WHERE ID=4
SELECT
Doc.value('(/ROOT/ROW[1]/ID/text())[1]','int') RootRowID1,
--
µÚÒ»ÐÐ
ID
µÄÖµ£¬²¢ÇÒת»»Îª
int
ÀàÐÍ
Doc.value('(/ROOT/ROW[2]/ID/text())[1]','int') RootRowID2,
--
µÚ¶þÐÐ
ID
µÄÖµ£¬²¢ÇÒת»»Îª
int
ÀàÐÍ
Doc.value('(/ROOT/ROW[1]/NAME/text())[1]','varchar(20)')
RootRowNAME1,
--
µÚÒ»ÐÐ
NAME
µÄÖµ£¬²¢ÇÒת»»Îª
VARCHAR
ÀàÐÍ
Doc.value('(/ROOT/ROW[1]/NAME/@SEX)[1]','varchar(20)')
RootRowNAME1SEX, --
µÚÒ»ÐÐ
NAME
ÖÐ
SEX
ÊôÐÔµÄÖµ£¬²¢ÇÒ×
Ïà¹ØÎĵµ£º
xmlÎļþ:
<?xml version="1.0" encoding="utf-8" ?>
<bookstore>
<book>
<title lang="eng">Harry Potter</title>
<price>29.99</price>
</book>
<book>
......
ÔÚÓÃAsp.net¶Ô±¸·ÝµÄÊý¾Ý¿âÎļþ½øÐл¹ÔµÄʱºò£¬ÓÐʱºò»á³öÏÖÏÂÃæµÄ´íÎóÒì³££º
[ÒòΪÊý¾Ý¿âÕýÔÚʹÓã¬ËùÒÔδÄÜ»ñµÃ¶ÔÊý¾Ý¿âµÄÅÅËü·ÃÎÊȨ¡£ RESTORE DATABASE ²Ù×÷Òì³£ÖÕÖ¹¡£Òѽ«Êý¾Ý¿âÉÏÏÂÎĸÄΪ 'master'¡£]
Õâ¸öʱºò£¬×ÔÓɵȴýÆäËû½ø³ÌÊͷŶÔӦȨÏ޺󣬲ſɻ¹Ô³É¹¦£¡ÓÐûÓнâ¾ö°ì·¨ÄØ£¿ÎÒ²ÎÕÕ¡¾Java¡¿¶ÔÕâ¸öÎÊÌâµÄ½â¾ö ......
1.ÔÚJSPÖÐÉú³É¶¯Ì¬XML
¿ÉÒÔʹÓÃJSPÉú³ÉXML,ʹÓÃCSS»òÕßXSLת»»ºÍÏÔʾXML;
Ö»ÒªÔÚ¾²Ì¬µÄXMLÎĵµÄ£°åÖмÓÈëJava´úÂëºÍJSP±ê¼Ç£¬XML¾Í¿ÉÒÔÓо²±ä¶¯£¬²úÉú¶¯Ì¬µÄÄÚÈÝ£¬Éú³ÉXMLÎĵµµÄ·½·¨ºÜ¼òµ¥£¬Ö»ÐèÒªÔÚÎļþÖÐʹÓÃÖ¸Áîcontenttype,Èç<%@ page contenttype="text/xml"%>£»
ÔÚXMLÎĵµÖÐͬÑù¿ÉÒÔʹ ......
ÁÙ½üÄêÖÕ£¬ÔÚ¹¤×÷Ö®Óà¶Ô¹¤×÷ºÍѧϰÖÐÓöµ½µÄÎÊÌâÒÔ¼°³£ÓõÄһЩ֪ʶµã×öÁËЩÕûÀí£¬ÒÔ±¸ºóÓᣱ¾ÎÄÉæ¼°µÄÄÚÈÝΪÊý¾Ý¿â,ËãÊǶԿª·¢×ܽá(1)---Êý¾Ý¿âÒ»ÎĵIJ¹³ä¡£
1 ¶ÔÓÚÖ÷¼üÉèÖÃÁËIdentityµÄ±í£¬ÔÚɾ³ý±íÖÐÊý¾ÝºóÔÙÍù±íÖвåÈëÊý¾Ý£¬IdentityÁв»ÊÇ´Ó1ÆðʼÁË£¬Èç¹ûÏëɾ³ýÊý¾ÝºóIndentityÁÐÈÔ´Ó1Æðʼ£¬¿ÉÒÔÓÃÏÂÃæ´úÂëÀ´É¾³ýÊý¾Ý ......
1¡¢³õʼ»¯
Load µ¼ÈëÒ»¸öXMLÎļþµ½CMarkupµÄ¶ÔÏóÖУ¬²¢¶ÔËü½øÐнâÎö¡£ÀàËÆC#µÄLoad¡£
SetDoc ´Ó×Ö·û´®Öе¼ÈëXMLÊý¾Ý£¬²¢¶ÔËü½âÎö¡£ÀàËÆC#µÄLoadXml¡£
2¡¢Êä³ö
Save ½«XMLÊý¾ÝдÈëÎļþÖС£ÀàËÆC#µÄSave¡£
GetDoc ½«Õû¸öXMLÊý¾ÝÎĵµ×÷Ϊ×Ö·û´®·µ»Ø¡£
3¡¢¸Ä±äµ±Ç°Î»ÖÃ
FindElem ¶¨Î»µ½ÏÂÒ»¸öÔªËØ£¬¿ÉÄܺÍÒ»¸ö±êÇ©Ãû»ò· ......