如何读取xml文件 [英] how to read the xml file
本文介绍了如何读取xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
i在我的D:驱动器中有xml文件我希望将反转的xml文件放到windows应用程序中并过滤xml数据,
怎么办呢
如果你知道plz帮助我。
hi
i have xml file in my D:drive i want retrive xml file into windows applications and filter the xml data,
how can do this
if u know plz help me.
推荐答案
看看XmlDocument [ ^ ],尤其是 XmlDocument.Load [ ^ ]方法。
Have a look at XmlDocument[^] and especially XmlDocument.Load[^] method.
看一下这篇文章。它展示了如何使用C#语言在Microsoft .NET中读取和写入XML文档。
在C#中读写XML [ ^ ]
祝你好运。
Take a look at this article. It shows how to read and write XML documents in Microsoft .NET using C# language.
Reading and Writing XML in C#[^]
Good luck.
采取此措施: http://stackoverflow.com/questions/5604330/c-sharp-xml-parsing-read-a-simple-xml-file-and-检索值 [ ^ ]
查看链接以读取示例xml,配置代码以适应您的xml文件< br $> b $ b
阅读XML
Took this off : http://stackoverflow.com/questions/5604330/c-sharp-xml-parsing-read-a-simple-xml-file-and-retrieve-values[^]
View Link to read the sample xml, configure to code to suite your xml file
Read XML
public void Read(string fileName)
{
XDocument doc = XDocument.Load(fileName);
foreach (XElement el in doc.Root.Elements())
{
Console.WriteLine("{0} {1}", el.Name, el.Attribute("id").Value);
Console.WriteLine(" Attributes:");
foreach (XAttribute attr in el.Attributes())
Console.WriteLine(" {0}", attr);
Console.WriteLine(" Elements:");
foreach (XElement element in el.Elements())
Console.WriteLine(" {0}: {1}", element.Name, element.Value);
}
}
在硬盘中打开XML文件:
To Open XML File in Hard Disk:
static void Main()
{
var assembly = Assembly.GetExecutingAssembly();
using (var stream = assembly.GetManifestResourceStream("ProjectName.test.xml"))
using (var reader = new StreamReader(stream))
{
Console.WriteLine(reader.ReadToEnd());
}
}
如果你发现这个有用的话请投票
Please vote if you found this usefull
这篇关于如何读取xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文