Microsoft.Protocols.TestSuites.Common.SchemaValidation.GetSchemaStringFromWsdlFile C# (CSharp) Method

GetSchemaStringFromWsdlFile() private static method

A method used to get the schema definitions from full WSDL file. It is designed to read schema definition from full WSDL file.
private static GetSchemaStringFromWsdlFile ( string schemaLoadPath ) : string[]
schemaLoadPath string A parameter represents a full WSDL file path where the schema definitions should be loaded.
return string[]
        private static string[] GetSchemaStringFromWsdlFile(string schemaLoadPath)
        {
            List<string> schemas = new List<string>();
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(schemaLoadPath);
            XmlNodeList wsdlTypes = xmlDoc.GetElementsByTagName("wsdl:types");
            XmlNodeList wsdlDefinitions = xmlDoc.GetElementsByTagName("wsdl:definitions");

            if (wsdlTypes != null && wsdlTypes.Count == 1)
            {
                foreach (XmlNode schemaElement in wsdlTypes[0].ChildNodes)
                {
                    if (schemaElement.NodeType != XmlNodeType.Comment)
                    {
                        foreach (XmlAttribute attribute in wsdlDefinitions[0].Attributes)
                        {
                            if (attribute.Prefix == "xmlns" && schemaElement.Attributes.GetNamedItem(attribute.Name) == null)
                            {
                                XmlAttribute namespaceAttribute = (XmlAttribute)attribute.Clone();
                                schemaElement.Attributes.Append(namespaceAttribute);
                            }
                        }

                        schemas.Add(schemaElement.OuterXml);
                    }
                }
            }

            return schemas.ToArray();
        }
    }