使用C#,我们如何才能从XML模式文件中提取属性值并将其输出到CSV文件中? [英] Using C#, how can we pull attribute values from an XML Schema file and output that onto a CSV file?

查看:82
本文介绍了使用C#,我们如何才能从XML模式文件中提取属性值并将其输出到CSV文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图提取该XMl Schema文件中每个元素的属性值.

I am trying to pull the attribute values for each of the element, that is in this XMl Schema file.

推荐答案

这是最简单的方法,可用于节点上的循环以获取每个节点中的信息. 使用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模式文件中提取属性值并将其输出到CSV文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆