Reputation: 167
So I'm currently working on a project right now involving C-Sharp, and it it frustrating me so much. Currently, I have to get text stored in a XML tag, read it as a string, and store it into a series of text boxes. However, for some reason, the text boxes keep nullifying each other out; they are erasing each other. What am I doing wrong? It's been bugging for a while now. Thank you!
XmlDocument generalXML = new XmlDocument();
generalXML.Load(generalURI);
// Connect to the web request for the resource you want
// In other words - create a socket with the uri
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(generalURI);
// Indicate that you will READ only (GET)
req.Method = "GET";
try
{
// get and store the response and convert it into a usable stream
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
Stream str = res.GetResponseStream();
// read the stream as an XML object
XmlReader xr = XmlReader.Create(str);
if (textBoxDescription.Text == "")
{
xr.ReadToFollowing("description");
textBoxDescription.Text = xr.ReadElementContentAsString();
}
if (textBoxWebsite.Text == "")
{
xr.ReadToFollowing("website");
textBoxWebsite.Text = xr.ReadElementContentAsString();
}
if (textBoxEmail.Text == "")
{
xr.ReadToFollowing("email");
textBoxEmail.Text = xr.ReadElementContentAsString();
}
if (textBoxName.Text == "")
{
xr.ReadToFollowing("name");
textBoxName.Text = xr.ReadElementContentAsString();
}
// close the ocnnection to the resource
res.Close();
}
catch
{
Console.Write("Error");
}
Upvotes: 0
Views: 59
Reputation: 2123
OK here is what is get from your question:
First of all your URI is not written correctly.
@"simon.ist.rit.edu:8080/Services/resources/ESD/"; + orgID + "/General";
change it to: (@"simon.ist.rit.edu:8080/Services/resources/ESD/" + orgID + "/General"
Secondly i think the textboxes are not filled correctly they are not nullifying each other. try:
XmlDocument document = new XmlDocument();
document.Load(@"http://simon.ist.rit.edu:8080/Services/resources/ESD/Organizations");
XmlNode OrganizationID= document.DocumentElement.SelectSingleNode("/data/row/OrganizationID");
string type= document.DocumentElement.SelectSingleNode("/data/row/type").InnerText.ToString();
string Name= document.DocumentElement.SelectSingleNode("/data/row/Name").InnerText.ToString();
string Email= document.DocumentElement.SelectSingleNode("/data/row/Email").InnerText.ToString();
string city= document.DocumentElement.SelectSingleNode("/data/row/city").InnerText.ToString();
string zip= document.DocumentElement.SelectSingleNode("/data/row/zip").InnerText.ToString();
string CountyName= document.DocumentElement.SelectSingleNode("/data/row/CountyName").InnerText.ToString();
string State= document.DocumentElement.SelectSingleNode("/data/row/State").InnerText.ToString();
Upvotes: 1