XML C# help

I am using Visual Studios and c#, i have quried a database and got the output that i need in an xml format.
What I want to do is style this format, could someone please help how do i go about doing this.
I have created a xsl style sheet but how do i link it to my project and where.
R8VIAsked:
Who is Participating?
 
Gautham JanardhanCommented:
public static void Transform(string sXmlPath, string sXslPath){
       
        try{
           
            //load the Xml doc
            XPathDocument myXPathDoc = new XPathDocument(sXmlPath) ;

            XslTransform myXslTrans = new XslTransform() ;
           
            //load the Xsl
            myXslTrans.Load(sXslPath) ;
           
            //create the output stream
            XmlTextWriter myWriter = new XmlTextWriter
                        ("result.html", null);
           
            //do the actual transform of Xml
            myXslTrans.Transform(myXPathDoc,null, myWriter);        

            myWriter.Close() ;


        }catch(Exception e){

            Console.WriteLine("Exception: {0}", e.ToString());
        }
       
    }
0
 
Gautham JanardhanCommented:
u can populate it into a dataset and then call the Dataset.WriteXML function().
0
 
R8VIAuthor Commented:
Thank You for that, is there a tutorial that I can follow please
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Gautham JanardhanCommented:
sorry i miss read ur question i think this is what u want

http://www.w3.org/TR/xml-stylesheet/
0
 
YZlatCommented:
can you give me an example of xml format?
0
 
YZlatCommented:
public void WriteXml(DataSet ds, string filePath )
            {
                  try
                  {
                        m_writer = new XmlTextWriter(filePath, System.Text.Encoding.UTF8);

                        m_writer.WriteStartDocument(true);

                        //<markers>
                        m_writer.WriteStartElement("markers");

                        //write the rest of the records
                        this.WriteRecords(ds.Tables[0]);

                        // </markers>
                         m_writer.WriteEndElement();

                        m_writer.WriteEndDocument();
                  }
                  catch (Exception ex)
                  {
                        Console.Write("ERROR: " + ex.Message);
                  }
                  finally
                  {
                        m_writer.Close();
                  }
            }

            private void WriteRecords(DataTable dt)
            {
                  try
                  {
                        foreach(DataRow dtRow in dt.Rows)
                        {
                              // <nodename>
                              m_writer.WriteStartElement("nodename");
                              m_writer.WriteAttributeString("attribute1", "", dtRow["field1"].ToString());
                                                            // </nodename>
                              m_writer.WriteEndElement();
                        }
                  }
                  catch (Exception ex)
                  {
                        Console.Write("ERROR: " + ex.Message);
                  }
      }
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.