Пример #1
0
        private static List<AttributeInfo> ParseXMLForAttributes(string xmlString)
        {
            XElement root;
            try
            {
                TextReader stringReader = new StringReader(xmlString);
                root = XElement.Load(stringReader);
            }
            catch (Exception e)
            {
                throw new ApplicationException(e.ToString());
            }

            var listAttributeInfo = new List<AttributeInfo>();

            if (root.HasElements)
            {
                foreach (XElement el in root.Elements())
                {
                    var attributeInfo = new AttributeInfo();
                    if (el.Name.ToString().Equals("SchemaTable"))
                    {
                        if (el.HasElements)
                        {
                            foreach (XElement el1 in el.Elements())
                            {
                                AddAttribute(attributeInfo, el1.Name, el1.Value);
                            }
                        }
                    }
                    listAttributeInfo.Add(attributeInfo);
                }
            }
            return listAttributeInfo;
        }
Пример #2
0
        private static void AddAttribute(AttributeInfo currentAttributeInfo, XName xNameValue, string valueIn)
        {
            string lastXMLTag = xNameValue.ToString();

            if (lastXMLTag.Equals("ColumnName"))
            {
                currentAttributeInfo.ColumnNameOriginal = valueIn;
            }
            else if (lastXMLTag.Equals("DataType"))
            {
                string dataType = valueIn;
                // get rid of anything after a comma
                currentAttributeInfo.DataType =
                    dataType.IndexOf(",", StringComparison.Ordinal) >= 0
                        ? dataType.Substring(0, dataType.IndexOf(",", StringComparison.Ordinal))
                        : dataType;

            }
            else if (lastXMLTag.Equals("ColumnSize"))
            {
                currentAttributeInfo.ColumnSize = Convert.ToInt32(valueIn);
            }
            else if (lastXMLTag.Equals("IsUnique"))
            {
                currentAttributeInfo.IsUnique = valueIn.ToUpper().Equals("TRUE") ? true : false;
            }
            else if (lastXMLTag.Equals("IsKey"))
            {
                currentAttributeInfo.IsKey = valueIn.ToUpper().Equals("TRUE") ? true : false;
            }
            else if (lastXMLTag.Equals("AllowDBNull"))
            {
                currentAttributeInfo.AllowDBNull = valueIn.ToUpper().Equals("TRUE") ? true : false;
            }
            else if (lastXMLTag.Equals("IsAutoIncrement"))
            {
                currentAttributeInfo.IsAutoIncrement = valueIn.ToUpper().Equals("TRUE") ? true : false;
            }
        }