to create xml file

Last post 09-10-2008 5:56 AM by Samu Zhang - MSFT. 3 replies.

Sort Posts:

  • to create xml file

    09-05-2008, 4:13 AM

    hi,

    I am retriving data in hierarchy form in XML by using FOR XML PATH it returns the XML data in a variable in c#. Now I want to read the conmtent of the variable to get node and their name and Id to display it on some control.  But unable to do that ..... Is it possible by using XMLREADER or XMLdocument ....If yes send me some link  or code if not the is it possible to make xml file from the content of the variable .........plz send me some link ..

    It is urgent

    thanks......... 

  • Re: to create xml file

    09-05-2008, 5:03 AM
    • Star
      9,462 point Star
    • kamii47
    • Member since 05-26-2005, 4:04 PM
    • Karachi, Pakistan
    • Posts 2,199

     You can retrieve Xml from database this way http://davidhayden.com/blog/dave/archive/2006/05/04/2936.aspx

    or

    use technique in following article http://www.sqlservercentral.com/articles/XML/62054/

     

    static void Main(string[] args)
    
            {
    
     
    
                //let us make a connection first
    
                String str;
    
                str = "Data Source=TOSHIBA-USER\\SQL2005;Initial Catalog=XmlTest;";
    
                str = str + "Persist Security Info=True;User ID=sa;Password=sa2005";
    
                SqlConnection cn = new SqlConnection(str);
    
                cn.Open();
    
     
    
                //Let us make a command
    
                SqlCommand cmd = new SqlCommand();
    
                cmd.Connection = cn;
    
                cmd.CommandText = "GetEmployeeData";
    
                cmd.CommandType = CommandType.StoredProcedure;
    
     
    
                //What we need next is an XMLReader and call
    
                //ExecuteXMLReader method of SqlCommand.
    
                XmlReader r;
    
                r = cmd.ExecuteXmlReader();
    
     
    
                //Read the data from XMLReader and Load into
    
                //the String Builder
    
                StringBuilder xmlData = new StringBuilder();
    
                while (r.Read())
    
                {
    
                    xmlData.Append(r.ReadOuterXml());
    
                }
    
     
    
                //Print the output
    
                Console.WriteLine(xmlData.ToString());
    
     
    
                //Close the Reader and DB Connection
    
                r.Close();
    
                cn.Close();
    
     
    
            }
      
    Kamran Shahid
    Sr. Software Engineer
    (MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])

    Remember to click "Mark as Answer" on the post that helps U
  • Re: to create xml file

    09-05-2008, 6:24 AM

    Thanks ......

    what u have given me are both very near to my need ....but I want to manuplate the content whatever we have got in the XMLDATA variable as I want to get every record one by one related to their parent and assibn it to some control. Is it possible ...........

    Thanks for the reply................

     

  • Re: to create xml file

    09-10-2008, 5:56 AM

    Hi santosh,

    Reply you here : http://forums.asp.net/t/1315275.aspx

     


    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Page 1 of 1 (4 items)