|
|
|
อยากทราบวิธีการใช้ C#(wpf) สร้าง xml ได้ยังไงบ้างคะ??...ผู้รู็ช่วยแนะนำหน่อยค่ะ ^^ |
|
|
|
|
|
|
|
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WpfApplication1
{
[Serializable]
public class QA
{
public string question { get; set; }
public string choice1 { get; set; }
public string choice2 { get; set; }
public string choice3 { get; set; }
public string choice4 { get; set; }
public QA()
{
}
public QA(string question, string c1, string c2, string c3, string c4)
{
this.question = question;
choice1 = c1;
choice2 = c2;
choice3 = c3;
choice4 = c4;
}
}
}
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
List<QA> qa = new List<QA>();
qa.Add(new QA("q1", "c1", "c2", "c3", "c4"));
qa.Add(new QA("q1", "c1", "c2", "c3", "c4"));
qa.Add(new QA("q1", "c1", "c2", "c3", "c4"));
qa.Add(new QA("q1", "c1", "c2", "c3", "c4"));
qa.Add(new QA("q1", "c1", "c2", "c3", "c4"));
qa.Add(new QA("q1", "c1", "c2", "c3", "c4"));
qa.Add(new QA("q1", "c1", "c2", "c3", "c4"));
qa.Add(new QA("q1", "c1", "c2", "c3", "c4"));
using (var sw = new System.IO.StreamWriter(@"c:\test.xml"))
{
var serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<QA>));
serializer.Serialize(sw, qa);
}
}
}
}
ลองดูครับ
|
|
|
|
|
Date :
2011-04-06 21:54:41 |
By :
numenoy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|