Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XML Explanation

XML Explanation

Scheduled Pinned Locked Moved XML / XSL
databasecsharpsharepointcom
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vimalsoft Pty Ltd
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • V Vimalsoft Pty Ltd

      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

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      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

      V 1 Reply Last reply
      0
      • L led mike

        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

        V Offline
        V Offline
        Vimalsoft Pty Ltd
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups