Sqlserver£º´ÓXMLÎļþÖжÁÈ¡ÅäÖÃÐÅÏ¢
ÈçºÎÔÚSqlserverÖдÓÍⲿXMLÎļþÖжÁÈ¡ÅäÖÃÐÅÏ¢ÄØ£¿¸ÃÎÊÌâÔ´×ÔÒ»¼ÒÆóÒµµÄ±ÊÊÔÐÅÏ¢ÓиС£
Ò»xmlÎļþÄÚÈÝ£º
<?xml version="1.0" encoding="utf-8"?>
<root>
<db name="ClientDB1" datasize="512MB" datagrowth="100MB" logsize="100MB" loggrowth ="50MB">
</db>
<db name="ClientDB2" datasize="1536MB" datagrowth="200MB" logsize="100MB" loggrowth ="100MB">
</db>
<db name="ClientDBN" datasize="1024MB" datagrowth="200MB" logsize="100MB" loggrowth ="80MB">
</db>
</root>
½Å±¾£º
declare @x xml
declare @hdocid int
/*´ÓÍⲿÎļþ¶ÁÈ¡ÎļþÄÚÈÝ
ÓкܶàÖÖ·½Ê½£º
xp_cmdshell µ÷ÓòÙ×÷ϵͳµÄÏÔʽÎı¾ÎļþÄÚÈݵÄÀ©Õ¹´æ´¢¹ý³Ì¡£
bcp.exe µ¼Èëµ¼³ö¹¤¾ß
openrowset¶ÁÈëÎı¾ÎļþÄÚÈÝ£¨sql2005µÃµ½ÔöÇ¿£©
bulk insertÓï¾ä
*/
select @x=bulkcolumn
from openrowset(bulk 'c:\db_conifig.xml',SINGLE_CLOB ) as t¡¡¡¡--sqlserver2005µÄÔöÇ¿bulkÓï·¨
--½âÎö³ÉxmlÊ÷ÐÎÎĵµÔÚÄÚ´æÖÐ
exec sp_xml_preparedocument @hdocid output,@x
--sqlserver½âÎö³É½á¹û¼¯µÄÐÎʽ£¬±ãÓÚʹÓ᣻òÕßÖ±½ÓÀûÓÃxmlÀàÐ͵ķ½·¨½âÎö£¡
select *
from openxml(@hdocid,'/root/db') with (name varchar(50),datasize varchar(50),datagrowth varchar(50),logsize varchar(50),loggrowth varchar(50))
Ïà¹ØÎĵµ£º
==========================================
xmlÎļþ
£¼?xml version="1.0" encoding="GB2312"?£¾
£¼RESULT£¾
£¼VALUE£¾
¡¡¡¡ £¼NO£¾A1234£¼/NO£¾
¡¡¡¡ £¼ADDR£¾ËÄ´¨Ê¡XXÏØXXÕòXX·X¶ÎXXºÅ£¼/ADDR£¾
£¼/VALUE£¾
£¼VALUE£¾
¡¡¡¡ £¼NO£¾B1234£¼/NO£¾
¡¡ ¡¡£¼ADDR£¾ËÄ´¨Ê¡XXÊÐXXÏçXX ......
½ñÌìÔÚÔËÓÃspringµÄPropertyPlaceholderConfigurerʱ·¢ÏÖÒ»¸öÓÐÒâ˼µÄÄÚÈÝ£¬µ±ÄãÔÚapplicationContextÖÐÅäÖÃÒ»¸öPropertyPlaceholderConfigurerµÄbeanʱ£¬ÓÐlocationºÍlocationsµÄÊôÐÔ£¬²»Ã÷˼Òâlocation¶ÔÓ¦Ò»¸ö.propertiesÎļþ£¬
locations¶ÔÓ¦¶à¸ö.propertiesÎļþ£¬³å×ÅÏë¿´Ò»ÏÂPropertyPlaceholderConfigurerµÄʵÏÖ»úÖ ......
¾³£»áÓõ½xmlÎļþ£¬ÄÚÈݼÓÔØ£¬ Èç¹ûʹÓÃlinq xmlÊ÷¼ÓÔØ£¬ÐèҪͨ¹ýXElementÀ࣬һÖÖ·½Ê½ÊÇÒÔ×Ö·û´®µÄÐÎʽ¼ÓÔØ£¬ÁíÍâÒ»ÖÖ·½Ê½ÊÇÒÔÎļþÐÎʽ¼ÓÔØ¡£ 1.ÒÔ×Ö·û´®ÐÎʽ¼ÓÔØ¡£ ÔÚXElementÀàÖУ¬Í¨¹ý¾²Ì¬µÄParse()·½·¨ ......
XMLÏÖÔÚÒѾ³ÉΪһÖÖͨÓõÄÊý¾Ý½»»»¸ñʽ,ËüµÄƽ̨ÎÞ¹ØÐÔ,ÓïÑÔÎÞ¹ØÐÔ,ϵͳÎÞ¹ØÐÔ,¸øÊý¾Ý¼¯³ÉÓë½»»¥´øÀ´Á˼«´óµÄ·½±ã¡£¶ÔÓÚXML±¾ÉíµÄÓ﷨֪ʶÓë¼¼Êõϸ½Ú,ÐèÒªÔĶÁÏà¹ØµÄ¼¼ÊõÎÄÏ×,ÕâÀïÃæ°üÀ¨µÄÄÚÈÝÓÐDOM(Document Object Model),DTD(Document Type Definition),SAX(Simple API for XML),XSD(Xml Schema Definition),XSLT(Exten ......