简体   繁体   中英

Using C#, how can we pull attribute values from an XML Schema file and output that onto a CSV file?

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

you can use System.Xml.Linq to get all the elements and the required attributes as below

        XDocument document = XDocument.Load(@"D:\New Text Document.xml");
        var eleCollection = document.Elements("element");

        foreach (var element in eleCollection)
        {
            var type = element.Attribute("Type").Value;
        }

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;
    }
}

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