簡體   English   中英

如何使用C#將xml文件中的子節點輸出到csv文件中

[英]how to output the child node from a xml file using C# into csv file

我有一個輸出CSV文件的應用程序。 在項目中,我有一個包含url的xml配置文件。

<url>http://localhost/test</url>

我正在嘗試實現將其從xml文件(例如http://localhost/test )的屬性輸出到csv文件的功能。

我需要將其輸出到file.WriteLine行代碼中,但是我不知道如何在xml文件中輸出url的內容。

我已經創建了XmlTextReader,但是仍然無法輸出網址

在這里,您有一部分代碼:

int count = xml.GetElementsByTagName("url").Count;

for (int i = 0; i < count; ++i)
    {
     url.Add(xml.GetElementsByTagName("url")[i].InnerText);
    }
XmlTextReader reader = new XmlTextReader("config.xml");
using (StreamWriter file = new StreamWriter(fs))                    
{
    file.WriteLine("ProjectID, ProjectTitle,PublishStatus,Length");
    for (int s = 0; s < pr.Length; ++s)
    {
        string[] UsersIDS = new string[] {""};
        UsersIDS = db.GetUsersList(pr[s].ProjectID);
        file.WriteLine( pr[s].ProjectID + '"' + ',' + '"' + pr[s].ProjectTitle + '"' + ',' + pr[s].PublishStatus + '"' + ',' + UsersIDS.Length); 

}//end of for

經過測試,我通過添加以下內容使其工作:

url[i].ToString()

不管怎么說,多謝拉

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM