XML Explanation
-
Good Afternoon Guys , i have never attempted to save Data to the Database from the XML FILE, i have the Following
// pass an object to this function // the attribute of the object tells the function which stored proc to call // the object itself is serialized to an xml string and passed to the database // the stored proc on the other side takes care of the behind the scenes details public static string SaveObjectToDB(object obj) { string sql = "", xml = "", result = ""; // populate the object from the database using the specified ID // loop through the attributes of the object/class // Look up the stored procedure attribute on the object to use the appropriate stored proc to save the object foreach (Attribute attr in obj.GetType().GetCustomAttributes(true)) { DBStoredProcAttribute dbSPAttr = attr as DBStoredProcAttribute; // check if the attribute is a DBStoredProcAttribute if (dbSPAttr != null) { // serialize the object to xml xml = SerializeObjectToXML(obj); // trim of the xml headers // Subject Structures can be longer than 8000 characters so must trim off the prefix in .Net for SubjectStructure objects xml = xml.Replace("\\\\r\\\\n", "").Replace("\\r\\n", "").Replace("<?xml version=\\"1.0\\" encoding=\\"utf-16\\"?>", ""); int StartPos=0; StartPos = xml.IndexOf("<SubjectStructure>"); if (StartPos > 0) { xml = xml.Substring(StartPos); } // run the sp for this type of object passing the xml for the object sql = dbSPAttr.SaveObjectSP + "'" + xml.Trim() + "'"; // stored proc for SaveObject ; // execute the stored proc result = ExecuteStoredProc(sql); } } return result; }
Can you please help Explain this Function code.If i can Directly save the data to the Database, why should i put it to XML First then SQL Thanks
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za
-
Good Afternoon Guys , i have never attempted to save Data to the Database from the XML FILE, i have the Following
// pass an object to this function // the attribute of the object tells the function which stored proc to call // the object itself is serialized to an xml string and passed to the database // the stored proc on the other side takes care of the behind the scenes details public static string SaveObjectToDB(object obj) { string sql = "", xml = "", result = ""; // populate the object from the database using the specified ID // loop through the attributes of the object/class // Look up the stored procedure attribute on the object to use the appropriate stored proc to save the object foreach (Attribute attr in obj.GetType().GetCustomAttributes(true)) { DBStoredProcAttribute dbSPAttr = attr as DBStoredProcAttribute; // check if the attribute is a DBStoredProcAttribute if (dbSPAttr != null) { // serialize the object to xml xml = SerializeObjectToXML(obj); // trim of the xml headers // Subject Structures can be longer than 8000 characters so must trim off the prefix in .Net for SubjectStructure objects xml = xml.Replace("\\\\r\\\\n", "").Replace("\\r\\n", "").Replace("<?xml version=\\"1.0\\" encoding=\\"utf-16\\"?>", ""); int StartPos=0; StartPos = xml.IndexOf("<SubjectStructure>"); if (StartPos > 0) { xml = xml.Substring(StartPos); } // run the sp for this type of object passing the xml for the object sql = dbSPAttr.SaveObjectSP + "'" + xml.Trim() + "'"; // stored proc for SaveObject ; // execute the stored proc result = ExecuteStoredProc(sql); } } return result; }
Can you please help Explain this Function code.If i can Directly save the data to the Database, why should i put it to XML First then SQL Thanks
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za
-
I don't understand. Are you asking what the code does? It sounds like you are asking why the person did it this way, there is no way we can know that.
led mike
hi Led I meant , Am new to XML, i wanted to Know what are these Functions do like
Attribute attr in obj.GetType().GetCustomAttributes(true))
xml.Replace("\\r\\n", "").Replace("\r\n", "").Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "");
StartPos = xml.IndexOf("<SubjectStructure>");
sql = dbSPAttr.SaveObjectSP + "'" + xml.Trim() + "'"; // stored proc for SaveObject ;
Am reading a book, to famirialize myself with XML Thank you
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za