<?xml version="1.0" encoding="gb2312" ?>
- <xml>
- <tables>
- <table>
- <tableRow>
<nameid>1</nameid>
<name>name</name>
<titleid>ttttttt</titleid>
<title>project1</title>
<userid>453</userid>
<username>admin</username>
</RESULTROW>
- <RESULTROW>
<nameid>1</nameid>
<name>name</name>
<titleid>ttttttt</titleid>
<title>project1</title>
<userid>453</userid>
<username>admin</username>
</tableRow>
</table>
</tables>
<ERRORINFO />
<CURRENTTIME>2010-10-18 23:04:45</CURRENTTIME>
<ISSUCCESS>true</ISSUCCESS>
</xml>
以上是xml的格式,根据userid查所有的值绑定到combobox中,
XmlDocument entityX = new XmlDocument();
entityX.Load(entityXmlString);
XmlNodeReader entityReader = new XmlNodeReader(entityX);
DataSet entityDS = new DataSet();
entityDS.ReadXml(entityReader);
entityReader.Close();
string caseid = ((System.Data.DataRowView)(comboBoxCases.SelectedItem)).Row.ItemArray[0].ToString(); comboBoxEntity.DataSource = null;
if (entityDS.Tables.Count > 3)
{
string caseids = "caseid='" + caseid + "'";
comboBoxEntity.Text = "---请选择---";
comboBoxEntity.DataSource = entityDS.Tables[3].Select(caseids);
comboBoxEntity.DisplayMember = "title"; }——————》我的代码,显示不出title这一列的值,请各位高手帮帮忙,谢了
- <xml>
- <tables>
- <table>
- <tableRow>
<nameid>1</nameid>
<name>name</name>
<titleid>ttttttt</titleid>
<title>project1</title>
<userid>453</userid>
<username>admin</username>
</RESULTROW>
- <RESULTROW>
<nameid>1</nameid>
<name>name</name>
<titleid>ttttttt</titleid>
<title>project1</title>
<userid>453</userid>
<username>admin</username>
</tableRow>
</table>
</tables>
<ERRORINFO />
<CURRENTTIME>2010-10-18 23:04:45</CURRENTTIME>
<ISSUCCESS>true</ISSUCCESS>
</xml>
以上是xml的格式,根据userid查所有的值绑定到combobox中,
XmlDocument entityX = new XmlDocument();
entityX.Load(entityXmlString);
XmlNodeReader entityReader = new XmlNodeReader(entityX);
DataSet entityDS = new DataSet();
entityDS.ReadXml(entityReader);
entityReader.Close();
string caseid = ((System.Data.DataRowView)(comboBoxCases.SelectedItem)).Row.ItemArray[0].ToString(); comboBoxEntity.DataSource = null;
if (entityDS.Tables.Count > 3)
{
string caseids = "caseid='" + caseid + "'";
comboBoxEntity.Text = "---请选择---";
comboBoxEntity.DataSource = entityDS.Tables[3].Select(caseids);
comboBoxEntity.DisplayMember = "title"; }——————》我的代码,显示不出title这一列的值,请各位高手帮帮忙,谢了
<RESULTROW>不闭合啊。
doc.Load("");
foreach (XmlNode node in doc.GetElementsByTagName("title"))
{}XmlDocument xmldoc=new XmlDocument();
xmldoc.LoadXml("");
XmlNodeList nodelist=xmldoc.SelectNodes("");
for(int i=0;i <nodelist.Count;i++)
{
XmlNodeList node= nodelist[i].ChildNodes;
for(int j=0;j <node.Count; j++)
{
comboBox1.Items.Add(node[j].InnerText);
}
}
<RESULTROW>是我太急忘记改了抱歉
XElement data = XElement.Load(@"D:\VisualStudioProject2008\CSDNAnswer\Linq2xml\Linq2xmlXpath\Linq2xmlXpath\data.xml"); var query = (from p in data.Descendants("tableRow")
where (string)p.Element("userid") == "453"
select new
{
titleid = (string)p.Element("titleid"),
title = (string)p.Element("title")
}).ToList(); this.comboBox1.DataSource = query;
this.comboBox1.DisplayMember = "title";
this.comboBox1.ValueMember = "titleid";
XmlDocument doc = new XmlDocument();
doc.LoadXml("...");
DataTable data = new DataTable();
data.Columns.Add("title");
data.Columns.Add("titleid"); foreach (XmlNode node in doc.GetElementsByTagName("tableRow"))
{
DataRow row = data.NewRow();
row["title"] = node.SelectSingleNode("title").InnerText + ":" + node.SelectSingleNode("titleid").InnerText;
row["titleid"] = node.SelectSingleNode("titleid").InnerText;
data.Rows.Add(row);
} this.comboBox1.DataSource = data;
this.comboBox1.DisplayMember = "title";
this.comboBox1.ValueMember = "titleid";
{
DataRow ...
}