the format i'm trying to read is as below:
-
-
-
I'm using the following code to read and display into a datagrid using http WebRequest.
DataSet
dsLookup.ReadXml(response.GetResponseStream());
dataGridView1.DataSource = dsLookup.Tables[0];
The problem is, it reads down to this line then stops:
-
even if i try to go past and display into a text field like below it still doesn't read past that problem line? is there a way to bypass the line above?
value_retailTextBox.Text = dsLookup.Tables[0].Rows[0][5].ToString();

VulpesRank #55 · 29.2K reputationPosted Feb 24, 2012, 10:25 AM EST
Stream s = response.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(s);
string xml = sr.ReadToEnd();
sr.Close();
xml = xml.Replace("- ", " "); // get rid of leading hyphens
XDocument xmlDoc = XDocument.Parse(xml);
You should then be able to use xmlDoc to read the elements you need using the LINQ to XML code you already have.
SenthilkumarRank #387 · 6.5K reputationPosted Feb 23, 2012, 1:16 AM EST
Here am not seeing some of the tags are not closed properly. That means the XML parsing will be failed in the DataSet ReadXML function.
mike DelvottiRank #7,298 · 244 reputationPosted Feb 23, 2012, 1:51 AM EST
-
-
-
I've just noticed that the line it stops at is an element. so what i really would like to do is display the element "new" + "retail" in textbox1 & textbox2, those are within valuation/match elements. I assume i have to load the xml without using a dataset then?
mike DelvottiRank #7,298 · 244 reputationPosted Feb 24, 2012, 7:31 AM EST
I'm reading the xml that is collected from the web (via another source) now after some experimenting it's the hyphen in front of the attribute causing the code to stop reading the xml as the first and second offending line below:
-
-
if i remove the hyphen ("-") from the front of the attribute my code below works just fine:
var valuation = from match in xmlDoc.Descendants("match")
select new
{
retail = match.Element("trade").Value,
};
foreach (var match in valuation)
{
value_retailTextBox.Text = match.retail;
}
I guess I'm asking if the is a way i can modify my code to remove the hyphen from in front of the attributes?
Poppa Wallace97 reputationPosted Feb 24, 2012, 1:07 PM EST
http://www.filehelpers.com/
mike DelvottiRank #7,298 · 244 reputationPosted Feb 26, 2012, 11:17 PM EST
Vulpes - once again that is a bang on solution and works a treat, I have one last question on this subject that you will no doubt see a simple way, the returns that display in my textbox I would really like to format as "F2" what would be the best way for me to achieve that in code, I tried it like below but it doesn't like my method ;(
var valuation = from match in xmlDoc.Descendants("match")
select new
{
retail = match.Element("retail").Value.ToString("F2"),// my sample here that doesn't work for F2 format?
trade = match.Element("trade").Value,
average = match.Element("average").Value,
firstnew = match.Element("new").Value,
};
foreach (var match in valuation)
{
value_retailTextBox.Text = match.retail;
value_tradeTextBox.Text = match.trade;
value_averageTextBox.Text = match.average;
value_newTextBox.Text = match.firstnew;
}
VulpesRank #55 · 29.2K reputationPosted Feb 26, 2012, 11:46 PM EST
mike DelvottiRank #7,298 · 244 reputationPosted Feb 27, 2012, 12:06 AM EST