Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# convert xml to list string

/// <summary>
        /// Convert xml to List
        /// </summary>
        /// <param name="xmlFilePath">XML FilePath</param>
        /// <returns>List of String</returns>
        public static List<string> ExtractXMLToList(string xmlFilePath)
        {
            var colHeaders = new List<string>();
            XmlDocument document = new XmlDocument();
            document.Load(xmlFilePath);

            foreach (XmlNode node in document.DocumentElement.ChildNodes)
            {
              
              	//hardcoded xml child node here = MappingData
              	//and attributes of TableField
                if (node.LocalName == "MappingData")
                {
                    var fieldName = node.Attributes["TableField"].Value;
                    colHeaders.Add(fieldName);
                }
            }

            return colHeaders;
        }

//This the sample xml
//<?xml version="1.0" standalone="yes"?>
//<root>
//      <MappingData TableField ="Order Received Date"/>
//</root>
 
PREVIOUS NEXT
Tagged: #convert #xml #list #string
ADD COMMENT
Topic
Name
4+4 =