i am trying search data in xml file. if found, it will popup MessageBox and display all the data found.
this is my code.
DataView dv;
DataSet ds = new DataSet();
ds.ReadXml("C:\\Users\\HDAdmin\\Documents\\SliceEngine\\SliceEngine\\bin\\Debug\\saya.xml");
dv = new DataView(ds.Tables[0]);
dv.Sort = "Name";
int index = dv.Find("Name");
if (index == -1)
{
MessageBox.Show("Item Not Found");
}
else
{
MessageBox.Show(dv[index]["Name"].ToString());
}
but it always said the item not found.
then i tried to do this.
XmlDocument xml = new XmlDocument();
xml.Load("C:\\Users\\HDAdmin\\Documents\\SliceEngine\\SliceEngine\\bin\\Debug\\saya.xml");
XmlNodeList xnList = xml.SelectNodes("/Patient/Patient/Name");
foreach (XmlNode xn in xnList)
{
string name = xn["Name"].InnerText;
listBox21.Items.Add(name);
}
for this code, i tried to put it into the listbox. by doing this, it said that it is a null object.
below is my xml file.
<Patient>
<Patient>
<Level>0</Level>
<Name>w</Name>
<Gender>0</Gender>
</Patient>
</Patient>
can anybody help me with this.
You have to consider your code is ok! But here’s the problem:
Becase xn represents
/Patient/Patient/Nameand you just need to do:to get its value.