1
我是新來的asp.net。我有一個XML文件,如下所示:提取XML數據,修改它並存儲在Excel文件中
<?xml version="1.0" encoding="iso-8859-1" ?>
<newsitem itemid="10000" id="root" date="1996-08-22" xml:lang="en">
<title>CHINA: China says hopeful on global nuclear test ban.</title>
<headline>China says hopeful on global nuclear test ban.</headline>
<dateline>BEIJING 1996-08-22</dateline>
<text>
<p>China said on Thursday it was hopeful a global nuclear test ban treaty could be approved by the U.N. </p>
<p>"China hopes that the treaty could be open for signature by the end of the year and that there .</p>
</text>
.....continue
XML文件是巨大的,我想that..i必須在<標題>只處理條款和<正文>每條新聞的領域。另外,我必須計算這些詞的頻率。
我試圖從標題和文本字段中提取文本。我獲得了標題字段的數據,但沒有獲取文本字段。而且,在標題領域,我沒有得到獨特的元素,元素正在重複。請幫幫我。
我試過的代碼是:
string filename = Server.MapPath("demo1.xml");
XmlTextReader reader = new XmlTextReader(filename);
XmlNodeType type;
while (reader.Read())
{
type = reader.NodeType;
if (type == XmlNodeType.Element)
{
if (reader.Name == "text")
{
reader.Read();
TextBox1.Text = reader.Value;
}
if (reader.Name == "title")
{
reader.Read();
ListBox1.Items.Add(reader.Value);
}
}
}
reader.Close();
}
在列表框,我得到的數據,但在文本框中我沒有得到數據。此外,我需要存儲巨大的XML數據並計算每個單詞的數量。例如china-2,表示-1並將其存儲在excel中。你會告訴我,我應該使用字符串生成器,如果是,如何?
爲此,使用'XDocument'和LINQ to XML。它會讓你的生活變得更容易。 – Yuck
@Yuck我不知道LINQ ,, – user2387900