I have code that submits a query and the results in xml format then get assigned to a string variable “tmp” I then provide this variable as a xml input to a function that uses a separate xslt stylesheet to convert the xml results into html.
XML:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<Results>
<Exchange>
<OLO>LSMIT</OLO>
<Name>Mitcham</Name>
</Exchange>
<Checks>
<Check id="adsl">
<Linecode>GGEZ</Linecode>
<Linespeed>2048</Linespeed>
<Matched>Address</Matched>
<Provider>BT ADSL</Provider>
<Type>BT xDSL</Type>
<Updated>2010-08-17</Updated>
</Check>
</Checks>
</Results>
XSLT Stylesheet:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<p>You are connected to the <b>
<xsl:for-each select="Results/Exchange">
<xsl:value-of select="Name"/>
</xsl:for-each>
</b> telephone exchange</p>
<br/>
<p>According to <b>
<xsl:for-each select="Results/Checks/Check">
<xsl:value-of select="Provider"/>
</xsl:for-each>
</b>, houses at your postcode should be able to suppor the following:</p>
<br/>
<table>
<tr>
<td>
<img src="/img/tick_BGAvailabilityChecker.png"></img>
</td>
<td>
up to
<xsl:for-each select="Results/Checks/Check">
<xsl:value-of select="Linespeed"/>
</xsl:for-each>
</td>
</tr>
</body>
</html>
</xsl:template>
I cant display the evalues of the following elements:
<Linecode>
<Linespeed>
<Matched>
I can however display the following elements just fine:
<Provider>
<Type>
<Updated>
All the above are childs of the element
Its a weird one, The question is why I can’t I display the values of the Linecode, Linespeed, Matched elemets?
I have spent far too much time on this without being able to firgure out what some elements are displaying and others not. Any ideas will be greatly appreciated,
Here is the code I wrote to submit the query and store the xml results to a string variable “tmp”:
void cmdSubmit_Click(object sender, EventArgs e)
{
//Variable declarations
string user = "PRIVATE";
string pass = "PRIVATE";
string phone = TextBox1.Text;
string postcode = TextBox2.Text;
string buildnum = TextBox3.Text;
string check = "adsl";
string option = "adsllinecheck";
string outputformat = "xml";
string url = String.Format("http://api.samknows.com/checker.do?user={0}&pass={1}&phone=
{2}&postcode={3}&buildingnum={4}&checks={5}&options{6}&output{7}", user, pass, phone,
postcode, buildnum, check, option, outputformat);
Uri uri = new Uri(url);
string data = "field-keywords=ASP.NET 3.5";
if (uri.Scheme == Uri.UriSchemeHttp)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Method = WebRequestMethods.Http.Post;
request.ContentLength = data.Length;
request.ContentType = "application/x-www-form-urlencoded";
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(data);
writer.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string tmp = reader.ReadToEnd();
After debuggin it seams that the elements are not being returned. However when I simply copy the query string into a browser the results in xml do display the elements in question.
Is there anything different that I can do in the way I submit the query to ensure all elements are returned?
Thanks
Turns out there was nothing wrong major wrong with the code. After ispecting the query string:
I noticed that the assignement operator (=) was missing from the options and output parameters. After adding those everything worked perfectly….
Silly mistake, Problems Solved in the end!
Thanks to all anyways for all he suggestions.