2011-09-19 115 views
0

我目前有一个带提交按钮和两个电话号码和邮编的文本字段的webpart。当电话号码和邮编输入文本文件并按下提交时,我希望能够提交查询字符​​串和外部API,然后在XML文档对象的表单中返回查询结果。然后,我需要使用XPath查询此对象以显示结果,然后格式化或将此结果转换为HTML。 首先:使用XPath查询XML文档对象

  1. 我所创建的XML文档对象(一类),但我也不太清楚,然后如何使用XPath检索结果查询此对象。

  2. 我也不太清楚如何连接起来的提交按钮执行上面提到的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点将非常感谢!

在此先感谢

回答

0

要使用XPath,你可以使用的方法SelectSingleNodeSelectNodesXmlDocument选择节点。

+0

好的,我会看看一个,但是如何在首先按下按钮时执行查询。 //创建查询到针对服务器 串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); 谢谢, –