[英]how to output the child node from a xml file using C# into csv file
I have an application that outputs an CSV file. 我有一个输出CSV文件的应用程序。 In the project I have a xml config file that contain a url. 在项目中,我有一个包含url的xml配置文件。
<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
). 我正在尝试实现将其从xml文件(例如http://localhost/test
)的属性输出到csv文件的功能。
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. 我需要将其输出到file.WriteLine
行代码中,但是我不知道如何在xml文件中输出url的内容。
I have created a XmlTextReader but I can't still output the url 我已经创建了XmlTextReader,但是仍然无法输出网址
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 不管怎么说,多谢拉
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.