處理XML文檔是我們經常需要進行的一項工作,尤其是在進行網絡服務相關編程時,比如更新RSS等。在.NET 3.5中引入了Linq To XML,使得XML文檔的讀寫已經大大簡化,而.NET 4.0中最新的dynamic特性,則將簡化發揮到了極致。以處理白雲黃鶴的“十大”為例,數據源地址為http://www.byhh.net/posttop10.xml,其當前內容為(為使結果顯示清晰,去掉了其中的鏈接地址字段):
<?xml version="1.0" encoding="gb2312" ?>
<?xml-stylesheet type="text/xsl" href="/style/blue/xsl/posttop.xsl"?>
<toppost>
<post>
<board>WorldSoccer</board>
<title>大家支持哪隊? </title>
</post>
<post>
<board>HUSTStudent</board>
<title>地震了??? </title>
</post>
<post>
<board>Picture</board>
<title>想當二奶的有門路了! </title>
</post>
<post>
<board>Picture</board>
<title>輕拍。。。不要太挑剔了 </title>
</post>
<post>
<board>Humor</board>
<title>【原創】幾個小humor </title>
</post>
<post>
<board>HUSTStudent</board>
<title>院士增選的一個疑問 </title>
</post>
<post>
<board>WorldSoccer</board>
<title>臥槽,1:55才開始抽?? </title>
</post>
<post>
<board>WorldSoccer</board>
<title>主持MM好靓 </title>
</post>
<post>
<board>TrainFan</board>
<title>1000 </title>
</post>
<post>
<board>Movies</board>
<title>還是推薦熊貓大俠,早上才十塊錢. </title>
</post>
</toppost