0
我目前有一個帶提交按鈕和兩個電話號碼和郵編的文本字段的webpart。當電話號碼和郵編輸入文本文件並按下提交時,我希望能夠提交查詢字符串和外部API,然後在XML文檔對象的表單中返回查詢結果。然後,我需要使用XPath查詢此對象以顯示結果,然後格式化或將此結果轉換爲HTML。 首先:使用XPath查詢XML文檔對象
我所創建的XML文檔對象(一類),但我也不太清楚,然後如何使用XPath檢索結果查詢此對象。
我也不太清楚如何連接起來的提交按鈕執行上面提到的XMLDocument對象的查詢字符串。
下面是XmlDocument對象,將查詢外部API,並返回結果中有代碼中沒有錯誤sugesting一切都很好,到目前爲止:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml; // needed for the XML document object
using System.Xml.XPath; //needed to use Xpath to query the XMLDocument object
using System.Xml.Xsl; //needed to convert xml into HTML hopefully
namespace ACWebPart.VisualWebPart1
{
public partial class VisualWebPart1UserControl : UserControl
{
private XmlDocument performXmlCheck(string user, string pass, string phone, string postcode,
string checks, string options)
{
//creating the XMLDocument object
XmlDocument xml = new XmlDocument();
//creating the query to run against the server
string url = String.Format("http://api.samknows.com/checker.do?user= {0} &pass={1} &phone={2}
&postcode={3} &checks={4} &options={5} &output=xml", user, pass, phone, postcode, checks,
options);
//to catch errors a try and catch will be created
try
{
//querying the server, parse the XML and store it
xml.Load(url);
}
catch
{
//if an execption is encountered (Server unreachable, HTTP500, HTTP 404, etc) return null
return null;
}
return xml;
}
protected void Page_Load(object sender, EventArgs e)
{
//creating the event habdler for the submit button
cmdSubmit.Click += new EventHandler(cmdSubmit_Click);
//Live validation of input text boxes to ensure they are not empty and have the correct input
format
TextBox1.Attributes.Add("OnFocus", "if(this.value == 'Phone number') {this.value='',
this.style.borderColor='#c4c4c4', this.style.color='#676767', this.style.fontStyle='normal'};");
TextBox1.Attributes.Add("OnBlur", "if(this.value == '') {this.value='Phone number',
this.style.color='red', this.style.fontStyle='italic', this.style.borderColor='red'};");
TextBox2.Attributes.Add("OnFocus", "if(this.value == 'Postcode's) {this.value='',
this.style.borderColor='#c4c4c4', this.style.color='#676767', this.style.fontStyle='normal'};");
TextBox2.Attributes.Add("OnBlur", "if(this.value == '') {this.value='Postcode',
this.style.color='red', this.style.fontStyle='italic', this.style.borderColor='red'};");
}
void cmdSubmit_Click(object sender, EventArgs e)
{
}
}
}
還沒有在2010年的Sharepoint做了很多與XML所以任何幫助和協助與上述第1點和第2點將非常感謝!
在此先感謝
好的,我會看看一個,但是如何在首先按下按鈕時執行查詢。 //創建查詢到針對服務器 串URL運行=的String.Format(「http://api.samknows.com/checker.do?user= {0}&傳= {1}&電話= {2} &postcode = {3}&checks = {4}&options = {5}&output = xml「,user,pass,phone,postcode,checking, options); 謝謝, –