Cần giúp tìm kiếm XML với C#

Wendy

Junior
Joined
Oct 13, 2010
Messages
213
Reactions
161
MR
0.029
Mình có một file XML như thế này
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Dictionary>
  <[B][COLOR="#FF0000"]Word[/COLOR][/B]>
    <English>a</English>
    <Phonetic> /ei, ə/</Phonetic>
    <Vietnamese> một; một (như kiểu); một (nào đó)</Vietnamese>
    <Example>System Information</Example>
  </Word>
  <Word
    <English>system</English>
    <Phonetic>/'sistim/</Phonetic>
    <Vietnamese>hệ thống; chế độ</Vietnamese>
    <Example>System Information</Example>
  </Word>
  <Word>
    <English>product</English>
    <Phonetic>/product/</Phonetic>
    <Vietnamese>sản vật, sản phẩm, vật phẩm</Vietnamese>
    <Example>System Information</Example>
  </Word>
  <Word> 
    <English>profit</English>
    <Phonetic>/profit/</Phonetic>
    <Vietnamese>ợi, lợi ích, bổ ích</Vietnamese>
    <Example>System Information</Example>
  </Word>
<Dictionary>

Mình tìm trên mạng thì thấy có hướng dẫn tìm kiếm nhưng nó lại phải có thuộc tính của <Word</Word>>(ở đây Word trong file của mình thì không có thuộc tính)..Đoạn code ví dụ đó như sau
Code:
        XmlNode node = null;
        private void button1_Click(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(Application.StartupPath + "/employees.xml");
            if (radioButton1.Checked)
            {
                node = doc.SelectSingleNode(string.Format("//employee[./firstname/text()='{0}']", textBox1.Text));

            }
            else
            {
                node = doc.SelectSingleNode(string.Format("//employee[./lastname/text()='{0}']", textBox1.Text));
            }
            if (node != null)
            {
                comboBox1.Items.Add(node.Attributes["employeeid"].Value);
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (node == null)
            {
                MessageBox.Show("Please select Employee ID");
                return;
            }
            label8.Text = node.ChildNodes[0].InnerText;
            label9.Text = node.ChildNodes[1].InnerText;
            label10.Text = node.ChildNodes[2].InnerText;
            label11.Text = node.ChildNodes[3].InnerText; 
        }
2.jpg
Nó sẽ hiển thị thế này..ĐÂY LÀ DEMO mình kiếm trên mạng..Nếu ai rành về cái này có thể giúp mình sửa đoạn code để tìm kiếm trong File XML của mình mà không cần Thuộc tính dc không ???. Nếu ai k hiểu thì cho mình xin Yahoo với nhé. Mình sẽ addd
 

Announcements

Today's birthdays

Forum statistics

Threads
423,791
Messages
7,133,274
Members
176,240
Latest member
duchungkhang

Most viewed of week

Most discussed of week

Most viewed of week

Most discussed of week

Back
Top Bottom