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

Linq to XML customize distinct function

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)
{
return obj.Attribute("Name").Value.GetHashCode();
}
}
How to use this one to distinct:
public List<string> LoadDistrict(string region)
{
if (m_DataDoc == null)
return null;
List<string> list = new List<string>();
try
{
var query = from r in m_DataDoc.Elements("DashBoardData").Elements("LevelData").Elements("Region").Where(a => a.Attribute("Name").Value.ToLower() == region.ToLower())
select r;
foreach (var district in query.Elements("District").Distinct(new ItemComparer()))
{
list.Add(district.Attribute("Name").Value);
}
return list;
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
return null;
}
}


Ïà¹ØÎĵµ£º

XMLÐòÁл¯(Ò»)

MSDNÉϵĶ¨Ò壺
XML ÐòÁл¯½«¶ÔÏóµÄ¹«¹²×ֶκÍÊôÐÔ»òÕß·½·¨µÄ²ÎÊýºÍ·µ»Øֵת»»£¨ÐòÁл¯£©Îª·ûºÏÌض¨ XML ¼Ü¹¹¶¨ÒåÓïÑÔ (XSD) ÎĵµµÄ XML Á÷¡£XML ÐòÁл¯Éú³ÉÇ¿ÀàÐ͵ÄÀ࣬²¢Îª´æ´¢»ò´«ÊäÄ¿µÄ½«Æ乫¹²ÊôÐÔºÍ×Ö¶Îת»»ÎªÐòÁиñʽ£¨ÔÚ´ËÇé¿öÏÂΪ XML)¼òµ¥µÄ˵¾ÍÊǽ«Ò»¸ö¶ÔÏóת»»³ÉXMLÁ÷»òÊÇÎļþµÄ¹ý³Ì¡£
×¢ÒâÊÂÏҪÐòÁл¯µÄÀ ......

XMLÐòÁл¯(Ò»)

MSDNÉϵĶ¨Ò壺
XML ÐòÁл¯½«¶ÔÏóµÄ¹«¹²×ֶκÍÊôÐÔ»òÕß·½·¨µÄ²ÎÊýºÍ·µ»Øֵת»»£¨ÐòÁл¯£©Îª·ûºÏÌض¨ XML ¼Ü¹¹¶¨ÒåÓïÑÔ (XSD) ÎĵµµÄ XML Á÷¡£XML ÐòÁл¯Éú³ÉÇ¿ÀàÐ͵ÄÀ࣬²¢Îª´æ´¢»ò´«ÊäÄ¿µÄ½«Æ乫¹²ÊôÐÔºÍ×Ö¶Îת»»ÎªÐòÁиñʽ£¨ÔÚ´ËÇé¿öÏÂΪ XML)¼òµ¥µÄ˵¾ÍÊǽ«Ò»¸ö¶ÔÏóת»»³ÉXMLÁ÷»òÊÇÎļþµÄ¹ý³Ì¡£
×¢ÒâÊÂÏҪÐòÁл¯µÄÀ ......

fw_student_SqlMap.xml(SQL ºÍVOµÄÓ³ÉäÎļþ)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="fw_student">
<resultMap class="com.sias.Student" id="student">
<result column="name" property="na ......

½âÎö_Net¿ò¼ÜϵÄXML±à³Ì¼¼Êõ

½âÎö_Net¿ò¼ÜϵÄXML±à³Ì¼¼Êõ
Ò»£®Ç°ÑÔ£º
        XMLÊÇ΢Èí.NetÕ½ÂÔµÄÒ»¸öÖØÒª×é³É²¿·Ö£¬¶øÇÒËü¿ÉνÊÇXML Web·þÎñµÄ»ùʯ£¬ËùÒÔÕÆÎÕ.Net¿ò¼ÜϵÄXML¼¼Êõ×ÔÈ»ÏԵ÷dz£ÖØÒªÁË¡£±¾ÎĽ«Ö¸µ¼´ó¼ÒÈçºÎÔËÓÃC#ÓïÑÔÍê³É.Net¿ò¼ÜϵÄXMLÎĵµµÄ¶Áд²Ù×÷¡£Ê×ÏÈ£¬ÎÒ»áÏò´ó¼Ò½éÉÜ.Net¿ò¼ÜÖÐÓëXMLÏà ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ