Exemplo n.º 1
0
        private async void button6_Click(object sender, EventArgs e)
        {
            richTextBox7.Clear();
            richTextBox8.Clear();


            try
            {
                // install xampp and put the sample file inside htdocs folder  and start xampp before sending the request

                string page = await client.GetStringAsync("http://localhost/sample.xml");

                richTextBox7.Text = page;


                XmlSerializer serializerXml = new XmlSerializer(typeof(DeveloperXml));

                using (var stringreader = new StringReader(page))
                {
                    DeveloperXml developerxml = (DeveloperXml)serializerXml.Deserialize(stringreader);

                    richTextBox8.AppendText(developerxml.Id.ToString() + Environment.NewLine);

                    richTextBox8.AppendText(developerxml.Name + Environment.NewLine);

                    richTextBox8.AppendText(developerxml.Salary.ToString() + Environment.NewLine);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            #region XML Serialization

            DeveloperXml developerXml = new DeveloperXml()
            {
                Id     = 1,
                Name   = "John",
                Salary = 2300
            };


            XmlSerializer serializerXml = new XmlSerializer(typeof(DeveloperXml));

            using (var stringwriter = new StringWriter())
            {
                serializerXml.Serialize(stringwriter, developerXml);

                richTextBox1.Text = stringwriter.ToString();
            }


            #endregion


            #region Json Serialization

            DeveloperJson developerJson = new DeveloperJson()
            {
                Id     = 1,
                Name   = "John",
                Salary = 2300
            };

            JavaScriptSerializer serializerJson = new JavaScriptSerializer();

            richTextBox2.Text = serializerJson.Serialize(developerJson);



            #endregion


            #region HTML region

            richTextBox5.Text = @"<!DOCTYPE html>
<html>

<p style='color:red'> This is a sample ! </p>
     

     </html>
     ";



            #endregion
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            XmlSerializer serializerXml = new XmlSerializer(typeof(DeveloperXml));

            using (var stringreader = new StringReader(richTextBox1.Text))
            {
                DeveloperXml developerxml = (DeveloperXml)serializerXml.Deserialize(stringreader);

                richTextBox3.AppendText(developerxml.Id.ToString() + Environment.NewLine);

                richTextBox3.AppendText(developerxml.Name + Environment.NewLine);

                richTextBox3.AppendText(developerxml.Salary.ToString() + Environment.NewLine);
            }
        }