// throws NullReferenceException /// <summary> /// parses <see cref="TableSchema"/> from <paramref name="tableSchemaXmlNode"/>. /// </summary> /// <param name="tableSchemaXmlNode"></param> /// <returns> /// <see cref="TableSchema"/> parsed from <paramref name="tableSchemaXmlNode"/> /// </returns> /// <exception cref="TableSchemaParseException"> /// thrown if <see cref="TableSchema"/> parse failed /// </exception> public static TableSchema Parse(XmlNode tableSchemaXmlNode) { try { // get required name attribute string tableName = tableSchemaXmlNode.GetAttributeValue("name"); // get optional notAuditable element bool auditable = !tableSchemaXmlNode.ContainsNodes("not_auditable"); // get table columns XmlNodeList columnSchemaXmlNodeList = tableSchemaXmlNode.GetNodes("column"); ColumnSchema[] columnSchemas = new ColumnSchema[columnSchemaXmlNodeList.Count]; for (int i = 0; i < columnSchemaXmlNodeList.Count; i++) { XmlNode columnSchemaXmlNode = columnSchemaXmlNodeList[i]; columnSchemas[i] = ColumnSchema.Parse(columnSchemaXmlNode); } // get primary key, if specified ColumnSchema primaryKeyColumnSchema = null; if (tableSchemaXmlNode.ContainsNodes("primary_key")) // primary key specified { int primaryKeyColumnIndex = tableSchemaXmlNode.GetNodes("primary_key")[0] .GetAttributeValue <int>("column_index"); primaryKeyColumnSchema = columnSchemas[primaryKeyColumnIndex]; } TableSchema tableSchema = new TableSchema( tableName, columnSchemas, primaryKeyColumnSchema, auditable); return(tableSchema); } catch (Exception exception) { if ( // exception while trying to parse TableSchema exception is XmlNodeMissingAttributeException || exception is XmlNodeMissingNodeException || exception is InvalidAttributeTypeException || exception is ColumnSchemaParseExcetion) { throw new TableSchemaParseException(null, exception); } else // unhandled exception { throw exception; } } }