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();
VulpesPosted Feb 24, 2012, 3:25 PM
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.
mike DelvottiPosted Feb 27, 2012, 5:06 AM
VulpesPosted Feb 27, 2012, 4:46 AM
mike DelvottiPosted Feb 27, 2012, 4:17 AM
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;
}
Poppa WallacePosted Feb 24, 2012, 6:07 PM
http://www.filehelpers.com/
mike DelvottiPosted Feb 24, 2012, 12:31 PM
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?
mike DelvottiPosted Feb 23, 2012, 6:51 AM
-
-
-
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?
SenthilkumarPosted Feb 23, 2012, 6:16 AM
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.