简体   繁体   中英

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

I have an application that outputs an CSV file. In the project I have a xml config file that contain a url.

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

What I am trying to achieve its to output into the csv file the attribute form the xml file (example http://localhost/test ).

I need to output this into the file.WriteLine line code but I don't know how to output the content of the url inside the xml file.

I have created a XmlTextReader but I can't still output the url

Here you have part of my code:

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

After testing I got it work by adding the following:

url[i].ToString()

Thanks anyways

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM