Êý¾Ý¿â²éѯXML½á¹¹£¬FOR XML PATH Óï¾äµÄÓ¦ÓÃ
/*
Êý¾Ý¿â²éѯXML½á¹¹£¬FOR XML PATH Óï¾äµÄÓ¦ÓÃ
*/
FOR XML PATH Óï¾äµÄÓ¦ÓÃ:
CREATE TABLE TempTable(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('')
select CAST(UserID AS varchar) + '',UserName + '' from TempTable FOR XML PATH('')
---ÔËÐÐÉÏÃæÕâ¾ä½«Éú³É½á¹û
----1a2b
----ËùÓÐÊý¾Ý¶¼Éú³ÉÒ»ÐУ¬¶øÇÒ»¹Ã»ÓÐÁ¬½Ó×Ö·û£¬ÕâÑùµÄÊý¾Ý¿ÉÄܶԴó¼ÒûÓÐÓô¦£¬»¹¿ÉÒÔÔٱ仯һÏ£º
select CAST(UserID AS varchar) + ',',UserName + '',';' from TempTable FOR XML PATH('')
select CAST(userid as varchar) +',' +username +';' from TempTable for xml path('')
----Éú³É½á¹û
1,a;2,b;
----´ó¼ÒÏÖÔÚÃ÷°×ÁË°É£¬¿ÉÒÔͨ¹ý¿ØÖƲÎÊýÀ´Éú³É×Ô¼ºÏëÒªµÄ½á¹û£¬ÀýÈ磺
select '{' + CAST(UserID A
Ïà¹ØÎĵµ£º
д±¾ÎĵÄÄ¿µÄÊÇΪÁË·½±ã´ó¼ÒÁ˽âC++ MSXML²Ù×÷·½·¨¡£
µ±È»£¬C++ÖжÔMSXMLµÄµ÷ÓÃÓжàÖÖ£¬±¾ÎIJÉÓõķ½·¨ÊÇÍêÈ«²ÎÕÕMSXML SDKÌṩµÄÎĵµ½øÐвÙ×÷¡£
Èç¹ûÓÐʲô´íÎ󣬻¶ÓÖ¸Õý¡£
´úÂë¿ò¼ÜÊÇ»ùÓÚvs2008 MFC ¶Ô»°¿ò³ÌÐò£¨UNICODE£©¡£¶Ô»°¿ò³ÌÐòÐèÒª¶ÁÕß×Ô¼º´´½¨¡£
#include <msxml6.h>
#include <comutil.h>
# ......
·Ò룺Çï·ã
Ô´úÂ룺
LoadingXmlInTvMTCode.zip
ÔںܶàÇé¿öϳÌÐòÔ±ÐèÒª²ÉÓöàÏß³ÌÀ´¿ª·¢Ó¦ÓóÌÐò£¬Óû§¿ÉÒÔÔÚǰ̨²Ù×÷Êý¾Ý»òÆäËû¹¤×÷£¬ÔÚºǫ́³ÌÐòÕýÔÚ¼ÓÔغܴóµÄһЩÎļþ£¬¶øÕâÒ»¹ý³Ì²»»áÓ°Ï쵽ǰ̨µÄÓû§¡£ÔÚÕâƪÎÄÕÂÖУ¬ÎÒÀ´½²ÊöÒ»ÏÂÔõÑùͨ¹ý¶à¸öÏß³ÌÀ´¼ÓÔضà¸öÎļþ¡£
ÔÚÕâ¸öÀý×ÓÖÐÎÒÃǽ«À´Ñо¿Õ ......
http://www.cnblogs.com/long2006sky/articles/1258731.html
DataSetת»»ÎªxmlÎļþ
//½«DataSetת»»ÎªxmlÎļþ
private static void ConvertDataSetToXMLFile(DataSet xmlDS, string xmlFile)
{
&n ......
×î½üÔÚ²©¿ÍÔ°´úÂëµÄÖع¹ÖÐ, ÎÒ·¢¾õÓÃDataTable.Select½øÐÐXMLÊý¾ÝµÄ²éѯҲÊÇͦ·½±ãµÄ¡£
±ÈÈçÎÒÃǸù¾ÝUrlÖвÎÊýÖµ²éѯXMLÊý¾ÝÖÐÏàÓ¦½ÚµãµÄÊý¾Ý¡£
¼ÙÈçÎÒÃÇÓÐÕâÑùµÄXmlÊý¾ÝÎļþCatalog.xml:
<Navigation>
<Catalog title="·Ç¼¼ÊõÇø" url="default.aspx?cate=2" rss="MainFeed.as ......
class ImportExportToExcel
{
public class ImportExportToExcel
{
private string strConn;
private System.Windows.Forms.OpenFileDialog openFileDlg = new System.Windows.Forms.OpenFileDialog();
private System.Windows.Forms.SaveFileDialog saveFi ......