Using C#, how can we pull attribute values from an XML Schema file and output that onto a CSV file?(使用 C#,我们如何从 XML Schema 文件中提取属性值并将其输出到 CSV 文件中?)
问题描述
我正在尝试提取每个元素的属性值,即在此 XMl Schema 文件中.
I am trying to pull the attribute values for each of the element, that is in this XMl Schema file.
推荐答案
这是一种最简单的方法,可以在节点上使用 for 循环来获取每个节点中的信息.使用 node.ChildNodes 属性来获取 chilenodes.
This is easiest way one can use for loops on nodes to get the information in each node. use node.ChildNodes property to get the chilenodes.
XmlDocument doc = new XmlDocument();
doc.Load("filepath");
//Here Path could be- "//ElementType" ---> this will give all nodes with name ElementType
XmlNodeList nodes= doc.SelectNodes("//give path of nodes you want attributes for");
foreach (XmlNode node in nodes)
{
//Assuming you want information of element tags
foreach (XmlNode child in node.ChildNodes)
{
string name= node.Attributes["type"].Value;
string name= node.Attributes["label"].Value;
}
}
这篇关于使用 C#,我们如何从 XML Schema 文件中提取属性值并将其输出到 CSV 文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 C#,我们如何从 XML Schema 文件中提取属性值


- C#MongoDB使用Builders查找派生对象 2022-09-04
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01