2016-04-07 18 views
-2

Bunun gibi bir xml dosyasına sahibim.xml dosyasından veriyi nasıl alabilirim

<?xml version="1.0"?> 
<Topic TopicName="FxhysS2vY64="> 
    <Question> 
    <QuestionID>HtjBCldKZg4=</QuestionID> 
    <Details>Cg+MCbd9nTpJokauVrxHsyTqcvKCS8ePzHQCpUTVviWxAXriQVLy5w==</Details> 
    <Description>x358GtJIXJI=</Description> 
    <TrueOrFalse>D2zx2u5cwbo=</TrueOrFalse> 
    <Points>W4VYuxBJeaY=</Points> 
    <QuestionType>Fr1jj5tmWhMKNIKrHy18Rg==</QuestionType> 
    <Caption>Cg+MCbd9nTpJokauVrxHsyTqcvKCS8ePAsNmzBfGJhg=</Caption> 
    <TopicID>HtjBCldKZg4=</TopicID> 
    </Question> 
    <Question> 
    <QuestionID>HtjBCldKZg4=</QuestionID> 
    <Details>ccX0bHUdtg4ayF/7PfpFHUx9kPAGUBC5xOh1mw1b7d1g0lHifJ6AD49Niw1ipCPp</Details> 
    <Description>x358GtJIXJI=</Description> 
    <TrueOrFalse>JYEB3R1+ypE=</TrueOrFalse> 
    <Points>W4VYuxBJeaY=</Points> 
    <QuestionType>Fr1jj5tmWhMKNIKrHy18Rg==</QuestionType> 
    <Caption>ccX0bHUdtg4ayF/7PfpFHUx9kPAGUBC5xOh1mw1b7d1g0lHifJ6AD49Niw1ipCPp</Caption> 
    <TopicID>HtjBCldKZg4=</TopicID> 
    </Question> 
</Topic> 

Ben bunu nasıl, DevExpress Benim gridcontrol Yani enter image description here

yılında gridcontrol içinde Datatable içine koymak ve göstermek istiyoruz. bence bu deneyin

+1

Lütfen temel kodlamayı yapmak için herhangi bir çevrimiçi eğiticiye başvurun ve sonra özel sorular sorun. – Sampada

+0

Evet, başka bir şey "Yapmam gerekeni öğrenmek için çok tembelim, ya da belgeleri oku, lütfen bana programlamayı öğret" sorusu. – TomTom

cevap

0

çok teşekkürler o İşte size

public DataTable ReadXML(string file) 
{ 
    DataTable table = new DataTable("XmlData"); 
    Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read); 
    table.Columns.Add("Name", typeof(string)); 
    table.Columns.Add("Power", typeof(int)); 
    table.Columns.Add("Location", typeof(string)); 
    table.ReadXml(stream); 
    return table; 
} 

yardımcı olacaktır tam referanstır:

İşte How to read XML into a DataTable?

0

çok az çalışma ile çok basit bir yöntemdir. Bir dosyadan okuyorsunuz, bu yüzden akışları kullanmaya gerek yok.

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     const string FILENAME = @"c:\temp\test.xml"; 
     public Form1() 
     { 
      InitializeComponent(); 
      DataSet ds = new DataSet(); 
      ds.ReadXml(FILENAME); 

      dataGridView1.DataSource = ds.Tables[1]; 
     } 
    } 
} 
İlgili konular