ͨ¹ýLINQ to XMLÉú³É XML
±êÇ©£ºÊý¾Ý·ÃÎÊ ADO.NET
ͨ¹ýLINQ to XMLÉú³É XML XML³£³£ÓÃÓïÔÚ¿Í»§»úºÍ·þÎñÆ÷Ö®¼ä½»Á÷Êý¾Ý£¬»òÕ߶à²ãÓ¦ÓóÌÐòÖ®¼ä½»Á÷¡£
ÓÃLINQ to SQL²éѯÊý¾Ý£¬ÔÙÓÃLINQ to XML°ÉÊý¾Ýת»»ÎªXML.
Àý£º
.......
AreslabDataContext aresData = new aresData(); //´´½¨DataContextʵÀý
XElement aresCustomerOrders = new XElement("customers", //´´½¨XMLƬ¶ÎʵÀý from c in aresData.Customers //ÀûÓÃLINQ²éѯÊý¾Ý£¬DataContext¶ÔÏóµÄCustomers³ÉÔ±×÷ΪÊý¾ÝÔ´ select new XElement("customer", //¹¹½¨selectͶÉä new XAtrribute("ID", c.CustomerID), new XAtrribute("Company", c.CompanyName),
Ïà¹ØÎĵµ£º
Definition comparer class,
class ItemComparer : IEqualityComparer<XElement>
{
public bool Equals(XElement x, XElement y)
{
return x.Attribute("Name").Value == x.Attribute("Name").Value;
}
public int GetHashCode(XElement obj)
......
/// <summary>
/// DataTable-------------------->XML --String
/// </summary>
public static String ToXmlString(DataTable dt)
{
StringWriter tr = new StringWriter();
try
{
dt.WriteXml(tr); ......
×î½üÔÚsina¿´nbaµÄÎÄ×ÖÖ±²¥µÄʱºò£¬¶ÔÍøÕ¾ÓÒϽǵÄÄÇÒ»¸öÁÄÌì´°¿Ú²úÉúÐËȤ£¬¾Í¾ö¶¨×Ô¼ºÒ²×öÒ»¸ö¡£
ÉÏÍø²é²é×ÊÁÏ£¬ÕâÑùµÄÁÄÌìÊÒÎ޷ǾÍÊÇÓû§ÊäÈëÊý¾Ý´«µ½·þÎñÆ÷±£´æ£¬È»ºóÓû§Ò³ÃæÔÙʵʱµØ´ÓÊý¾Ý¿âÈ¡³öÊý¾Ý£¬ÏÔʾÔÚÒ³ÃæÉÏ£¬¼´¿ÉÍê³ÉÒ»´ÎÁÄÌì²Ù×÷¡£
Ê×ÏÈÎÒ¶¨ÒåÁËÒ»¸öxmlÎļþ£¬ÓÃÓÚ±£´æÓû§ ......
ÏÖÔÚÎÒÃÇÔÝÇÒʹÓÓ¼Çʱ¾”À´´´½¨ÎÒÃǵÄXMLÎļþ°É¡£ÏÈ¿´Ò»¸öXMLÎļþ£º
¡¡¡¡Àý1
¡¡¡¡¡´?xml version="1.0" encoding="gb2312" ?¡µ
¡¡¡¡¡´²Î¿¼×ÊÁÏ¡µ
¡¡¡¡ ¡´Êé¼®¡µ
¡¡¡¡ ¡´Ãû³Æ¡µXMLÈëÞ«½â¡´/Ãû³Æ¡µ
¡¡¡¡ ¡´×÷Õß¡µÕÅÈý¡´/×÷Õß¡ ......
package com.jcauto.action;
import java.util.ArrayList;
import java.util.List;
public class ContentRsp {
private String resultCode;
List<ContentInfo> contentList = new ArrayList<ContentInfo>();
public void addContent(ContentInfo contentInfo) {
contentList.add(contentI ......