Asked by:
Unable to parse the xml

Question
-
User-2001205625 posted
I need to call a .ashx handler and i will found a xml response that i need to convert into an datatble and bind to the gridview.
Dear friend whenever i try to parse the following XML
<?xml version="1.0" encoding="utf-8" ?> - <DocumentElement> - <Result> <id display="Unique id">5384</id> <PATIENT_ID>123456</PATIENT_ID> <TEST_TYPE display="URS10">URS10</TEST_TYPE> <TIME_STAMP display="TIME">2014-01-04T17:04:00+00:00</TIME_STAMP> <MORNING_SAMPLE display="MORNING SAMPLE">true</MORNING_SAMPLE> <GLUCOSE display="GLUCOSE">2</GLUCOSE> <BILIRUBIN display="BILIRUBIN">Large +++</BILIRUBIN> <KETONE display="KETONE">Negative</KETONE> <SPECIFIC_GRAVITY display="SPECIFIC GRAVITY">1.030</SPECIFIC_GRAVITY> <BLOOD display="BLOOD">Small +</BLOOD> <PH display="PH">6.5</PH> <PROTEIN display="PROTEIN">+</PROTEIN> <UROBILINOGEN display="UROBILINOGEN" unit="EU/dL">Normal or 0.2</UROBILINOGEN> <NITRITE display="NITRITE">Positive</NITRITE> <LEUKOCYTES display="LEUKOCYTES">Small +</LEUKOCYTES> </Result> </DocumentElement>
and load it in the Dataset with the following code i get every row as table in the dataset but i need to read the <Result></Result> as a table.
Dim request As WebRequest Dim response As HttpWebResponse Dim dataStream As Stream Dim ds = New DataSet("Response") Dim responseFromServer As String Dim reader As StreamReader Dim dt As DataTable request = WebRequest.Create("http://gcInformation.net/GetResult.ashx?patient_id=123456&username=sreyas&password=sreyas") response = CType(request.GetResponse(), HttpWebResponse) dataStream = response.GetResponseStream() reader = New StreamReader(dataStream) responseFromServer = reader.ReadToEnd() ds.ReadXml(XmlReader.Create(New StringReader(responseFromServer))) dt = ds.Tables(0)
Please help me .
Monday, April 7, 2014 2:33 AM
All replies
-
User-902516579 posted
Hi,
Consider using LINQ to XML to limit the results of your query.
HTH, Benjamin
Monday, April 7, 2014 6:05 AM -
User1140095199 posted
Hi,
and load it in the Dataset with the following code i get every row as table in the dataset but i need to read the <Result></Result> as a table.Refer to the Code Below. It's in C#. But I hope it is fairly easy to understand.
string responseFromServer = doc.InnerXml; DataSet ds = new DataSet(); ds.ReadXml(new StringReader(responseFromServer)); DataTable tb1 = ds.Tables[0]; GridView1.DataSource = tb1; GridView1.DataBind();
The above code shall read the string to XML and finally to DataTable, DataTable can be displayed using GridView.
Best Regards!
Wednesday, April 9, 2014 10:47 PM -
User910199987 posted
ReadXml method of DataSet Convert every Node as table and attributes name as column. so you can manually parse this XML using XmlNode and set in grid view or DataTable.
thanks
_________________________________________________________________________________________________________________________________________________________________________________________________
If you satisfy with that suggestion than mark as answer otherwise explain your question in detail
Thursday, August 27, 2015 8:34 AM