Reading data from xml file

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi I have problem in reading xml file. The things what I want to read is :<br/>
<br/>
"cmpd_name","cmpdnr","rt","mz","i","a","sn","z".<br/>
<br/>
Here there may be several values for each "mz","i","a","sn" in different lines under a "cmpd_name" (It will be clear if you see the attched xml file). Each of these ("mz","i","a","sn")
values under a "cmpd_name" should be seperated by "," and should store in the table in a single cell.<br/>
<br/>
for example that table for first "cmpd_name" should look like this:<br/>
<br/>
This is a single row and different columns in the table and I want to separate the "mz" and "i" values based on "z" which are in the same attribute<br/>
<div style="color:black; background-color:white
<pre> mz i a sn z<br/>

1. 285.13449609, 4896.99, 15532.5,2415.5 6.409,1 1<br/>

286.13775204 764.038<br/>

2. 285.13449609, 4896.99, 15532.5,2415.5 6.409,1 2<br/>

286.13775204 764.038<br/>

[/code]

<div style="color:black; background-color:white
<pre><span style="color:blue private

<span style="color:blue void

button1_Click(<span style="color:blue object

sender, EventArgs e)<br/>

{<br/>

<span style="color:blue string

key = <span style="color:#a31515 ""

;<br/>

<br/>

OpenFileDialog f = <span style="color:blue new

OpenFileDialog();<br/>

<span style="color:blue if

(f.ShowDialog() == DialogResult.OK)<br/>

{<br/>

textBox1.Text = f.FileName;<br/>

<br/>

}<br/>

XmlDocument xml = <span style="color:blue new

XmlDocument();<br/>

XmlTextReader reader1 = <span style="color:blue new

XmlTextReader(<span style="color:#a31515 ""

+ textBox1.Text + <span style="color:#a31515 ""

);<br/>

reader1.WhitespaceHandling = WhitespaceHandling.None;<br/>

reader1.Read();<br/>

<span style="color:green // MessageBox.Show("ok");

<br/>

<span style="color:blue while

(reader1.Read())<br/>

{<br/>

<br/>

<span style="color:blue while

(reader1.MoveToNextAttribute())<br/>

{<br/>

<span style="color:green // MessageBox.Show("ok1");

<br/>

<span style="color:blue if

(reader1.Name == <span style="color:#a31515 "cmpd_name"

)<br/>

{<br/>

textBox2.Text=reader1.Value;<br/>

<span style="color:green // MessageBox.Show("text2 = "+textBox2.Text);

<br/>

<br/>

}<br/>

<span style="color:blue if

(reader1.Name == <span style="color:#a31515 "mz"

)<br/>

{<br/>

<span style="color:blue if

(key == <span style="color:#a31515 ""

)<br/>

{<br/>

key = textBox2.Text;<br/>

}<br/>

<span style="color:blue if

(key == textBox2.Text)<br/>

{<br/>

<span style="color:blue if

(textBox3.Text == <span style="color:#a31515 ""

)<br/>

{<br/>

textBox3.AppendText(reader1.Value);<br/>

}<br/>

<span style="color:blue else

<br/>

{<br/>

<br/>

textBox3.AppendText(<span style="color:#a31515 ","

+ reader1.Value);<br/>

<br/>

}<br/>

}<br/>

<span style="color:blue else

<br/>

{<br/>

key = textBox2.Text;<br/>

textBox3.Clear();<br/>

textBox3.AppendText(reader1.Value);<br/>

}<br/>

<span style="color:green // MessageBox.Show(textBox3.Text);

<br/>

}<br/>

<span style="color:blue if

(reader1.Name == <span style="color:#a31515 "i"

)<br/>

{<br/>

<span style="color:blue if

(key == <span style="color:#a31515 ""

)<br/>

{<br/>

key = textBox2.Text;<br/>

}<br/>

<span style="color:blue if

(key == textBox2.Text)<br/>

{<br/>

<span style="color:blue if

(textBox4.Text == <span style="color:#a31515 ""

)<br/>

{<br/>

textBox4.AppendText(reader1.Value);<br/>

}<br/>

<span style="color:blue else

<br/>

{<br/>

<br/>

textBox4.AppendText(<span style="color:#a31515 ","

+ reader1.Value);<br/>

<br/>

}<br/>

}<br/>

<span style="color:blue else

<br/>

{<br/>

key = textBox2.Text;<br/>

textBox4.Clear();<br/>

textBox4.AppendText(reader1.Value);<br/>

}<br/>

<span style="color:green // MessageBox.Show(textBox4.Text);

<br/>

}<br/>

<span style="color:blue if

(reader1.Name == <span style="color:#a31515 "z"

)<br/>

{<br/>

<span style="color:blue if

(key == <span style="color:#a31515 ""

)<br/>

{<br/>

key = textBox2.Text;<br/>

}<br/>

<span style="color:blue if

(key == textBox2.Text)<br/>

{<br/>

<span style="color:blue if

(textBox5.Text == <span style="color:#a31515 ""

)<br/>

{<br/>

textBox5.AppendText(reader1.Value);<br/>

}<br/>

<span style="color:blue else

<br/>

{<br/>

<br/>

textBox5.AppendText(<span style="color:#a31515 ","

+ reader1.Value);<br/>

<br/>

}<br/>

}<br/>

<span style="color:blue else

<br/>

{<br/>

key = textBox2.Text;<br/>

textBox5.Clear();<br/>

textBox5.AppendText(reader1.Value);<br/>

}<br/>

<span style="color:green // MessageBox.Show(textBox4.Text);

<br/>

}<br/>

<br/>

<span style="color:blue if

(reader1.Name == <span style="color:#a31515 "rt"

)<br/>

{<br/>

textBox6.Text = reader1.Value;<br/>

}<br/>

<span style="color:blue if

(reader1.Name == <span style="color:#a31515 "cmpdnr"

)<br/>

{<br/>

textBox7.Text = reader1.Value;<br/>

}<br/>

<span style="color:blue if

(reader1.Name == <span style="color:#a31515 "a"

)<br/>

{<br/>

<span style="color:blue if

(key == <span style="color:#a31515 ""

)<br/>

{<br/>

key = textBox2.Text;<br/>

}<br/>

<span style="color:blue if

(key == textBox2.Text)<br/>

{<br/>

<span style="color:blue if

(textBox8.Text == <span style="color:#a31515 ""

)<br/>

{<br/>

textBox8.AppendText(reader1.Value);<br/>

}<br/>

<span style="color:blue else

<br/>

{<br/>

<br/>

textBox8.AppendText(<span style="color:#a31515 ","

+ reader1.Value);<br/>

<br/>

}<br/>

}<br/>

<span style="color:blue else

<br/>

{<br/>

key = textBox2.Text;<br/>

textBox8.Clear();<br/>

textBox8.AppendText(reader1.Value);<br/>

}<br/>

<span style="color:green // MessageBox.Show(textBox8.Text);

<br/>

}<br/>

<span style="color:blue if

(reader1.Name == <span style="color:#a31515 "sn"

)<br/>

{<br/>

<span style="color:blue if

(key == <span style="color:#a31515 ""

)<br/>

{<br/>

key = textBox2.Text;<br/>

}<br/>

<span style="color:blue if

(key == textBox2.Text)<br/>

{<br/>

<span style="color:blue if

(textBox9.Text == <span style="color:#a31515 ""

)<br/>

{<br/>

textBox9.AppendText(reader1.Value);<br/>

}<br/>

<span style="color:blue else

<br/>

{<br/>

<br/>

textBox9.AppendText(<span style="color:#a31515 ","

+ reader1.Value);<br/>

<br/>

}<br/>

}<br/>

<span style="color:blue else

<br/>

{<br/>

key = textBox2.Text;<br/>

textBox9.Clear();<br/>

textBox9.AppendText(reader1.Value);<br/>

}<br/>

<span style="color:green // MessageBox.Show(textBox9.Text);

<br/>

}<br/>

<span style="color:blue if

(reader1.Name == <span style="color:#a31515 "res"

)<br/>

{<br/>

<span style="color:blue if

(key == <span style="color:#a31515 ""

)<br/>

{<br/>

key = textBox2.Text;<br/>

}<br/>

<span style="color:blue if

(key == textBox2.Text)<br/>

{<br/>

<span style="color:blue if

(textBox10.Text == <span style="color:#a31515 ""

)<br/>

{<br/>

textBox10.AppendText(reader1.Value);<br/>

}<br/>

<span style="color:blue else

<br/>

{<br/>

<br/>

textBox10.AppendText(<span style="color:#a31515 ","

+ reader1.Value);<br/>

<br/>

}<br/>

}<br/>

<span style="color:blue else

<br/>

{<br/>

key = textBox2.Text;<br/>

textBox10.Clear();<br/>

textBox10.AppendText(reader1.Value);<br/>

}<br/>

<span style="color:green // MessageBox.Show(textBox10.Text);

<br/>

}<br/>

<span style="color:blue if

(reader1.Name == <span style="color:#a31515 "deconvoluted_molecular_mass"

)<br/>

{<br/>

<span style="color:blue if

(key == <span style="color:#a31515 ""

)<br/>

{<br/>

key = textBox2.Text;<br/>

}<br/>

<span style="color:blue if

(key == textBox2.Text)<br/>

{<br/>

<span style="color:blue if

(textBox11.Text == <span style="color:#a31515 ""

)<br/>

{<br/>

textBox11.AppendText(reader1.Value);<br/>

}<br/>

<span style="color:blue else

<br/>

{<br/>

<br/>

textBox11.AppendText(<span style="color:#a31515 ","

+ reader1.Value);<br/>

<br/>

}<br/>

}<br/>

<span style="color:blue else

<br/>

{<br/>

key = textBox2.Text;<br/>

textBox11.Clear();<br/>

textBox11.AppendText(reader1.Value);<br/>

}<br/>

<span style="color:green //MessageBox.Show(textBox11.Text);

<br/>

}<br/>

<span style="color:blue if

(key != textBox2.Text)<br/>

{<br/>

OdbcCommand Odbc11 = <span style="color:blue new

OdbcCommand();<br/>

<span style="color:green // k = k + 1;

<br/>

Odbc11.CommandText = <span style="color:#a31515 "insert INTO s_Metabolite_mining (FeatureNr, Retensiontime, Charge, mzlist, Intensitylist, Rel_Intensitylist, Arealist, SNlist, Deconvolutedlist) VALUES ("

+ textBox7.Text + <span style="color:#a31515 ","

+ textBox6.Text + <span style="color:#a31515 ","

+ textBox5.Text + <span style="color:#a31515 ","

+ textBox3.Text + <span style="color:#a31515 ","

+ textBox4.Text + <span style="color:#a31515 ","

+ textBox8.Text + <span style="color:#a31515 ","

+ textBox9.Text + <span style="color:#a31515 ","

+ textBox10.Text + <span style="color:#a31515 ","

+ textBox11.Text + <span style="color:#a31515 ")"

;<br/>

<br/>

Odbc11.Connection = OdbcCon;<br/>

OdbcCommand Odbc = <span style="color:blue new

OdbcCommand();<br/>

Odbc11.Connection = OdbcCon;<br/>

<br/>

Odbc11.ExecuteNonQuery();<br/>

MessageBox.Show(<span style="color:#a31515 "ok1"

);<br/>

}<br/>

<br/>

<br/>

}<br/>

reader1.MoveToElement();<br/>

<br/>

<br/>

}<br/>

}<br/>

[/code]

for this the code I have done up to my knowledge.

Please help me out.

The link for file is

http://www.easy-share.com/1913154425/Test2.xml
Thanks

View the full article
 
Back
Top