Link to home
Create AccountLog in
Avatar of R8VI
R8VI

asked on

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.
Avatar of Gautham Janardhan
Gautham Janardhan

u can populate it into a dataset and then call the Dataset.WriteXML function().
Avatar of R8VI

ASKER

Thank You for that, is there a tutorial that I can follow please
sorry i miss read ur question i think this is what u want

http://www.w3.org/TR/xml-stylesheet/
ASKER CERTIFIED SOLUTION
Avatar of Gautham Janardhan
Gautham Janardhan

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
can you give me an example of xml format?
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);
                  }
      }