public bool Consume_Xml_Structure_PlantBOM(string strFilename) { string strRefNo = ""; bool flag = false; SqlDataLayer objSql = new SqlDataLayer(); SqlParameter[] objParameters = new SqlParameter[4]; SqlParameter[] objParameters1 = new SqlParameter[1]; XmlDocument doc = new XmlDocument(); System.IO.StreamReader sr = new System.IO.StreamReader(strFilename); XmlNodeList Plant; XmlNodeList Zone; XmlNodeList Line; XmlNodeList Station; StringWriter sw = new StringWriter(); while (!sr.EndOfStream) { string strLine = sr.ReadLine(); if (strLine.StartsWith("<") == true && strLine.EndsWith(">") == true) { sw.WriteLine(strLine); } } try { doc.LoadXml(sw.ToString()); DataSet ds = new DataSet(); objParameters1[0] = new SqlParameter("@RESULT", SqlDbType.VarChar, 500); objParameters1[0].Direction = ParameterDirection.Output; strRefNo = objSql.ExecuteProcedureParam(SqlDataLayer.strLocal, "sp_GetRefNo", objParameters1, "@RESULT", "@RESULT"); Plant = doc.GetElementsByTagName("Plant"); foreach (XmlNode x in Plant) { ds = ConverttYourXmlNodeToDataSet(x); if (ds.Tables.Contains("Plant") == true) { if (ds.Tables["Plant"].Rows.Count == 0) { flag = false; } else { flag = true; } } else { flag = false; } } if (flag == true) { Station = doc.GetElementsByTagName("Station"); foreach (XmlNode x in Station) { ds = ConverttYourXmlNodeToDataSet(x); if (ds.Tables.Count > 0) { objParameters[0] = new SqlParameter("@TEMP_PARENT", SqlDbType.Structured); objParameters[1] = new SqlParameter("@TEMP_CHILD", SqlDbType.Structured); objParameters[2] = new SqlParameter("@FLAG", SqlDbType.VarChar); objParameters[3] = new SqlParameter("@REFNO", SqlDbType.VarChar); objParameters[0].Value = ds.Tables[0]; if (ds.Tables.Count > 1) { objParameters[1].Value = ds.Tables[1]; } objParameters[2].Value = "STATION"; objParameters[3].Value = strRefNo; objSql.ExecuteProcedure_DataSet(SqlDataLayer.strLocal, "sp_PlantBOM", objParameters); } } Line = doc.GetElementsByTagName("Line"); foreach (XmlNode x in Line) { ds = ConverttYourXmlNodeToDataSet(x); if (ds.Tables.Count > 0) { objParameters[0] = new SqlParameter("@TEMP_PARENT", SqlDbType.Structured); objParameters[1] = new SqlParameter("@TEMP_CHILD", SqlDbType.Structured); objParameters[2] = new SqlParameter("@FLAG", SqlDbType.VarChar); objParameters[3] = new SqlParameter("@REFNO", SqlDbType.VarChar); objParameters[0].Value = ds.Tables[0].DefaultView.ToTable(true, "ID", "NAME", "REVISION", "SUBTYPE"); if (ds.Tables.Count > 1) { objParameters[1].Value = ds.Tables[1].DefaultView.ToTable(true, "CHILD_ID"); } objParameters[2].Value = "LINE"; objParameters[3].Value = strRefNo; objSql.ExecuteProcedure_DataSet(SqlDataLayer.strLocal, "sp_PlantBOM", objParameters); } } Zone = doc.GetElementsByTagName("Zone"); foreach (XmlNode x in Zone) { ds = ConverttYourXmlNodeToDataSet(x); if (ds.Tables.Count > 0) { objParameters[0] = new SqlParameter("@TEMP_PARENT", SqlDbType.Structured); objParameters[1] = new SqlParameter("@TEMP_CHILD", SqlDbType.Structured); objParameters[2] = new SqlParameter("@FLAG", SqlDbType.VarChar); objParameters[3] = new SqlParameter("@REFNO", SqlDbType.VarChar); objParameters[0].Value = ds.Tables[0].DefaultView.ToTable(true, "ID", "NAME", "REVISION", "SUBTYPE"); if (ds.Tables.Count > 1) { objParameters[1].Value = ds.Tables[1].DefaultView.ToTable(true, "CHILD_ID"); } objParameters[2].Value = "ZONE"; objParameters[3].Value = strRefNo; objSql.ExecuteProcedure_DataSet(SqlDataLayer.strLocal, "sp_PlantBOM", objParameters); } } Plant = doc.GetElementsByTagName("Plant"); foreach (XmlNode x in Plant) { ds = ConverttYourXmlNodeToDataSet(x); if (ds.Tables.Count > 0) { objParameters[0] = new SqlParameter("@TEMP_PARENT", SqlDbType.Structured); objParameters[1] = new SqlParameter("@TEMP_CHILD", SqlDbType.Structured); objParameters[2] = new SqlParameter("@FLAG", SqlDbType.VarChar); objParameters[3] = new SqlParameter("@REFNO", SqlDbType.VarChar); objParameters[0].Value = ds.Tables[0].DefaultView.ToTable(true, "ID", "NAME", "REVISION", "SUBTYPE"); //objParameters[1].Value = ds.Tables[1].DefaultView.ToTable(true, "CHILD_ID"); objParameters[2].Value = "PLANT"; objParameters[3].Value = strRefNo; objSql.ExecuteProcedure_DataSet(SqlDataLayer.strLocal, "sp_PlantBOM", objParameters); } } return(flag); } else { return(flag); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { objParameters = null; objSql = null; doc = null; sr.Close(); sr = null; sw.Close(); sw = null; Plant = null; Zone = null; Line = null; Station = null; } }