我使用的是維基API來創建一個C#程序,其中一個關鍵字和搜索用戶類型(如果用戶搜索數據庫中的XML網址是:。https://en.wikipedia.org/w/api.php?action=query&list=allcategories&acmin=10&acprefix=database&acprop=size|hidden&format=xml&aclimit=500一個下拉框與內部文本當用戶選擇填充。?從下拉框中選擇不同的內部文本對象,列表框中應填寫了子類我無法弄清楚如何填補的子類別框有誰知道whow我會做到這一點這是CS的代碼,我到目前爲止有:如何使用Xml REST查詢中的Xml屬性填充ListBox?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml; //needed for XML processing
using System.Net; //needed for HttpWebRequest processing
public partial class WikiExcercise : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string URL = "https://en.wikipedia.org/w/api.php?action=query&list=allcategories&acmin=10&acprefix=" + txtKeyword.Text +
"&acprop=size|hidden&format=xml&aclimit=500";
//create an xml document and locad it from the web service
XmlDocument xmlDoc = new XmlDocument();
//need to indicate a legitimate user againt (not faking from the browser)
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.UserAgent = "My application";
xmlDoc.Load(request.GetResponse().GetResponseStream());
XmlNodeList list = xmlDoc.SelectNodes("/api/query/allcategories/c[@subcats>0]");
//databind the drop down list to the XmlNodeList
ddlCategories.DataTextField = "InnerText";
ddlCategories.DataSource = list;
ddlCategories.DataBind();
}
protected void ddlCategories_SelectedIndexChanged(object sender, EventArgs e)
{
string URL = "https://en.wikipedia.org/w/api.php?action=query&list=allcategories&acmin=10&acprefix=" + txtKeyword.Text +
"&acprop=size|hidden&format=xml&aclimit=500";
//create an xml document and locad it from the web service
XmlDocument xmlDoc = new XmlDocument();
//need to indicate a legitimate user againt (not faking from the browser)
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.UserAgent = "My application";
xmlDoc.Load(request.GetResponse().GetResponseStream());
XmlNodeList Xn = xmlDoc.SelectNodes("/api/query/allcategories/c[@subcats>0]/@subcats");
lstSubCategories.DataTextField = "InnerText";
lstSubCategories.DataSource = Xn;
lstSubCategories.DataBind();
foreach (XmlNode xNode in Xn)
{
lstSubCategories.Items.Add("boo");
lstSubCategories.DataTextField = "InnerText";
//lstSubCategories.Items.Add(xNode.Attributes["subcats"].Value);
}
}
}