Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

sqlserver FOR XML PATH Óï¾äµÄÓ¦ÓÃ

´úÂëÈçÏÂ:

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
ÔËÐÐÕâ¶Î½Å±¾£¬½«Éú³ÉÈçϽá¹û£º
¸´ÖÆ´úÂë
´úÂëÈçÏÂ:

<row>
<UserID>1</UserID>

<UserName>a</UserName>
</row>
<row>

<UserID>2</UserID>
<UserName>b</UserName>

</row>

´ó¼Ò¿ÉÒÔ¿´µ½Á½ÐÐÊý¾ÝÉú³ÉÁËÁ½¸ö½Úµã£¬ÐÞ¸ÄÒ»ÏÂPATHµÄ²ÎÊý£º
select
UserID,UserName from @TempTable FOR XML PATH('lzy')
ÔÙ´ÎÔËÐÐÉÏÊö½Å±¾£¬½«Éú³ÉÈçϵÄ
½á¹û£º
¸´ÖÆ´úÂë
´úÂëÈçÏÂ:

<lzy>
<UserID>1</UserID>

<UserName>a</UserName>
</lzy>
<lzy>

<UserID>2</UserID>
<UserName>b</UserName>

</lzy>

¿ÉÒÔ¿´µ½½Úµã±ä³É£¬ÆäʵPATH()
À¨ºÅÄڵIJÎÊýÊÇ¿ØÖƽڵãÃû³ÆµÄ£¬ÕâÑùµÄ»°´ó¼Ò¿ÉÒÔ¿´Ò»ÏÂÈç¹ûÊÇ¿Õ×Ö·û´®£¨²»ÊÇûÓвÎÊý£©»áÊÇʲô½á¹û?
select
UserID,UserName from @TempTable FOR XML PATH('')
Ö´ÐÐÉÏÃæÕâ¶Î½Å±¾½«Éú³É½á¹û£º
¸´ÖÆ´úÂë
´úÂëÈçÏÂ:

<UserID>1</UserID>
<UserName>a</UserName>

<UserID>2</UserID>
<UserName>b</UserName>


ÕâÑù¾Í²»ÏÔʾÉϼ¶½ÚµãÁË£¬´ó¼ÒÖªµÀÔÚ PATH ģʽÖУ¬ÁÐÃû»òÁбðÃû±»×÷Ϊ XPath
±í´ïʽÀ´´¦Àí£¬Ò²¾ÍÊÇ˵£¬ÊÇÁеÄÃû×Ö£¬ÕâÑù´óµ¨ÊÔÑéһϲ»¸øÖ¸¶¨ÁÐÃûºÍ±ðÃû»áÊÇÔõôÑù£¿
select CAST(UserID AS
varchar) + '',UserName + '' from @TempTable FOR XML PATH('')
ÔËÐÐÉÏÃæÕâ¾ä½«
Éú³É½á¹û
1a2b
ËùÓÐÊý¾Ý¶¼Éú³ÉÒ»ÐУ¬¶øÇÒ»¹Ã»ÓÐÁ¬½Ó×Ö·û£¬ÕâÑùµÄÊý¾Ý¿ÉÄܶԴó¼ÒûÓÐÓô¦£¬»¹¿ÉÒÔÔٱ仯һÏ£º
select
CAST(UserID AS varchar) + ',',UserName + '',';' from @TempTable FOR XML
PATH('')
Éú³É½á¹û
1,a;2,b;
´ó¼ÒÏÖÔÚÃ÷°×ÁË°É£¬¿ÉÒÔͨ¹ý¿ØÖƲÎÊýÀ´Éú³É×Ô¼ºÏëÒªµÄ½á¹û£¬
ÀýÈ磺
select '{' + CAST(UserID AS varchar) + ',','"' +UserName +
'"','}' from @TempTable FOR XML PATH('')
Éú³É½á¹û
{1,"a&q


Ïà¹ØÎĵµ£º

XML DOM½éÉÜ ÐÄÓêÖ®¼Ò web¿ª·¢

XML DOM½éÉÜ
 
Ò»¡¢XML DOM¼ò½é
DOM£¨Document Object Model£¬Îĵµ¶ÔÏóÄ£ÐÍ£©ÊÇÒ»ÖÖÓ¦ÓóÌÐò½Ó¿Ú£¨API£©µÄÓ¦Óã¬Ëü½«Îĵµ£¨ÈçXMLÎĵµ£¬HTMLÎĵµµÈ£©¿´³ÉÊÇÒ»¸öÎĵµ¶ÔÏó£¬È»ºóͨ¹ý³ÌÐòÓïÑÔ£¨ÈçJavaScriptµÈ½Å±¾ÓïÑÔ£¬C++µÈ£©µ÷ÓøÃÎĵµ¶ÔÏ󣬶ÔÎĵµÖеÄÊý¾Ý½øÐдæÈ¡£¬²¢ÀûÓóÌÐò¶Ô»ñÈ¡µÄÊý¾Ý½øÐиú½øÒ»²½µÄ´¦Àí¡£
X ......

SQLServerµÄËø»úÖÆ

×î½üÒòΪҪдһ¸öÊý¾Ý²¢·¢·ÃÎʵĿØÖƳÌÐò£¬ÉÏÍø²éÁËһЩ×ÊÁÏ£¬ÏÖÔÚ¹éÄÉÈçÏ£º ËøµÄ¸ÅÊö Ò». ΪʲôҪÒýÈëËø
¶à¸öÓû§Í¬Ê±¶ÔÊý¾Ý¿âµÄ²¢·¢²Ù×÷ʱ»á´øÀ´ÒÔÏÂÊý¾Ý²»Ò»ÖµÄÎÊÌ⣺
¶ªÊ§¸üÐÂ
A£¬BÁ½¸öÓû§¶ÁͬһÊý¾Ý²¢½øÐÐÐ޸ģ¬ÆäÖÐÒ»¸öÓû§µÄÐ޸Ľá¹ûÆÆ»µÁËÁíÒ»¸öÐ޸ĵĽá ......

Microsoft SqlServer 2005 ͨÓ÷ÖÒ³ ´æ´¢¹ý³Ì

±¾À´ÎÒÊDz»ÔÞ³ÉʹÓÃͨÓô洢¹ý³ÌµÄ£¬Ö÷ÒªÊÇÒòΪ¸ù¾Ý±í½á¹¹À´¶¨ÖÆ·ÖÒ³²éѯ²»Óö¯Ì¬µÄÆ´SQL£¬ÕâÑù²ÅÊÇÕæÕýµÄ¸ßЧ£¬¶øÇÒֻҪд¹ýÒ»¸ö£¬ÄÇôÔÙÓÐÐÂÐèÇóµÄʱºò£¬Ð¡·¶Î§¸Ä¶¯¼¸´¦¾ÍokÁË¡£
µ«×ÜÊÇÓÐÈËÏòÎÒÌÖÒª»òÕßÌÖÂÛͨÓô洢¹ý³Ì£¬Ã»°ì·¨£¬±»±ÆÎÞÄΣ¬Á¼ÐÄÉ¥ÓëÀ§¾³¡£
ľÓÐÕÒµ½T-SQL´úÂë±à¼­Æ÷
-- ============================= ......

ʹÓÃXMLµÄ³¡ºÏ

ÔںܶàÑÐÌÖ»áºÍÅàѵ°àÉÏÎÒÓöµ½¹ýÐí¶àÈË£¬ËûÃÇ»¹²»Ã÷°×ΪʲôҪʹÓÃXMLÒ²²»ÖªµÀÈçºÎÔÚËûÃǵÄÓ¦ÓÃÖÐʹÓÃXML¡£Ò»Ð©À´×ÔÖîÈçGartner¹«Ë¾µÄ±¨¸æ½¨Òé˵£¬ÉÌÒµ¹«Ë¾²»ÄÜÔÙ×ö¾ÖÍâÈËÁË£¬²»ÄܶÔXMLÖÃÖ®²»Àí¡£Èç¹ûÄ㻹²»Çå³þXMLµ½µ×ÓÐʲôºÃ´¦µÄ»°£¬Äã²¢²»ÊÇΨһµÄÈË¡£
ÎÒ¾ö¶¨°ÑÓëÈËÃǺÍýÌå¹ØÓÚXML»°ÌâµÄ½»Ì¸ÕûÀí³ÉÎÄ£¬ÁгöXMLÔÚÓ¦ÓÃÖ ......

JAVAÓëXML_¶ÁÊé±Ê¼Ç_2010 05 14

JAVATMÓëXML 2010-05-14
Ò»¡¢¸ÅÄî
l  ÈκÎXMLÎĵµ¶ÔÈκÎÀàÐ͵ÄÓ¦ÓÃÒÔ¼°ÕýÈ·µÄ½âÎö¶¼±ØÐë¾ßÓÐÁ¼ºÃµÄ½á¹¹well-formed
l  XMLÎĵµ¿ÉÒÔÊÇÓÐЧµØ£¨valid£©£¬µ«²¢·ÇÒ»¶¨ÒªÇóÓÐЧ¡£
l  PI£¨processing instruction£©¸ñʽ£º<?target instructions?>¡£XMLÖеĴ¦ÀíÖ¸ÁîÖ»ÄÜÊǽâÎöÆ÷¿ÉÒÔʶ±ðµÄXML±ê×¼´¦ÀíÃüÁ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ