linq¶ÁÈ¡xml»òtxtÎļþ - .NET¼¼Êõ / LINQ
linqÈçºÎ½«Ò»¸öxml»òtxtÎļþÀïµÄÄÚÈÝÈ«²¿¶ÁÈ¡³öÀ´£¬²¢¸³Öµ¸øÒ»¸ö¶àÐÐÎı¾¿ò¡£»¹ÓÐÎÊÌâ¾ÍÊÇÈçºÎÈÃÄÚÈÝÔÚ¶àÐÐÎı¾¿òµÄ¸ñʽÏÔʾ¸ú֮ǰÔÚtxt»ò xmlÎļþÀïµÄ¸ñʽһÑù¡£Çë¸ßÊÖ°ï°ïæ¡£¡£
ѧϰÖÐ...
StreamReader sr=new StreamReader(...);
richtextbox1.Text=sr.ReadToEnd();
StreamReader sr=new StreamReader(...);
richtextbox1.Text=sr.ReadToEnd();
XDocument xdoc = XDocument.Load(Server.MapPath("A.xml"));
XElement xe = new XElement("name", "");
xdoc.Element("user").Element("name").Add(xe);
var query = from P in xdoc.Descendants("name")
select P.Value
TXT
Ö±½ÓʹÓÃFile.ReadAllLines("")
Â¥Ö÷µÄÎÊÌâºÍ Linq ÓÐʲô¹Øϵ°¡£¿
Â¥Ö÷˵µÄ Linq ÊÇÖ¸ Linq to Xmlô£¿
Linq to Xml Êä³ö Xml ʱ£¬SaveOptionsÖ»ÓÐÈýÖÖ¸ñʽ°É£º
DisableFormatting ²»Ê¹ÓÃËõ½ø£¨Preserve all insignificant white space while serializing£©
None ʹÓÃËõ½ø
OmitDuplicateNamespaces ÒƳýÖظ´µÄÃüÃû¿Õ¼äµÄ¶¨Òå
Èç¹ûÔÚÔʼµÄ xml µÄ±êÇ©¶ÔÖ®ÍâÌí¼ÓÁË¿Õ¸ñ¡¢¸ü¸ÄËõ½ø£¬ÄÇô Linq to Xml ÊDz»¿ÉÄÜÖªµÀµÄ¡£
Äѵ½Ëµlinq ¼¼Êõ¾Í²»ÄÜ°Ñxml¡¢txt¡¢pdfÎļþÀïµÄÄÚÈÝÔ±¾µÄ¶Á³öÀ´Âð£¿ÓÐûÓÐÖªµÀµÄ¡£¸ßÊÖ°ï°ïæ°¡£¡£¡
C# code
Code highl
Ïà¹ØÎÊ´ð£º
ÏÖÔÚÓиöxmlÎļþÊÇ<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xm ......
XMLÎļþÄÚÈÝ£º
- <ResList>
<page>0</page>
- <resItem>
<resName>WWW</resName>
</resItem>
- <resItem>
&nb ......
xmlÎļþ¸ñʽÈçÏÂ
XML code:
<?xml version="1.0" encoding="GB2312" ?>
<allproducts version="1.0">
<products>
<product name="prodId&quo ......
htmlÒ³Ã澲̬´´½¨xmlÎļþ£¬²¢±£´æ£¬ÒÔºó¿ÉÒÔ¶ÁÈ¡¡£
²»ÖªÄÄλ´óÏÀ×ö¹ý¡£¡£¡£
лл
javascriptÓ¦¸Ã²»ÄÜ´´½¨Îļþ°É
jsÓÐȨÏÞ´´½¨Ã´£¬´ó¶àÊýÇé¿öϱ»½ûÖ¹°É
ȨÏÞ¡£¡£
ÀúÊ·ÒÅÁôÎÊÌ⣬¿´À´½â¾ö²»ÁËÁË¡£¡£¡£¡£¡ ......
ÎÒÏë°ÑXMLÎļþµÄÿÌõÄÚÈݷŵ½Ò»¸ö¶ÔÏóÖУ¬È»ºóÔÙ½«¶ÔÏó·Åµ½dictionaryÖмûÒ»¸öË÷Òý£¬¸ÃÈçºÎ×ö°¡£¿Çë½Ì¸ßÊÖÖ¸µã£¡
Èç°ÑÏÂÃæµÄÎļþÖÐÿÌõѧÉúÐÅÏ¢·Åµ½¶ÔÏóÖС£
<ѧÉú»¨Ãû²á>
<ѧÉú>
&n ......