返回首页

如何读从一个节点列表框的值:

ListBox listBox1 = new ListBox();

string fileName = (Server.MapPath("OrgList.xml"));

XPathDocument doc = new XPathDocument(fileName);

XPathNavigator nav = doc.CreateNavigator();

// Compile a standard XPath expression

XPathExpression expr;

expr = nav.Compile("/main/DATA_RECORD");

XPathNodeIterator iterator = nav.Select(expr);

// Iterate on the node set

listBox1.Items.Clear();

try

{

   while (iterator.MoveNext())

   {

      XPathNavigator nav2 = iterator.Current.Clone();

      listBox1.Items.Add(nav2.Value);

   }

}

catch (Exception ex)

{

   Response.Write(ex.ToString());

}
在程序中的数据记录是节点中有3个项目(姓名,学历,和ID)。与节点的iteraor传递和循环通过所有节点,添加到列表框中的所有节点。现在,我想分别访问3件。什么是它的语法?

回答