Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


I am having a Stored Procedure which was returning a XML file. By using Linq i want to display the result. My XML file coming from Stored Procedure is like this....

HTML
<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <ErrorMessage />
  <responseStatusMessage>521</responseStatusMessage>
  <statusDescription> Description follows</statusDescription>
  <Number>4621</Number>
  <original>2122</original>
  <dlmEnabled />
  <line>321</line>
</Response>


By writting an LINQ statement i want to display the above values. Can you please help me


Regards,
S.Inayat Basha
Posted
Updated 7-Dec-11 6:34am
v3
Comments
[no name] 7-Dec-11 12:33pm    
What part of it do you need help with? Have you tried anything?
RaviRanjanKr 7-Dec-11 17:56pm    
sure! but please be clear while asking question.

Hi

I guess you are not querying any recurring values or by any condition. Just a set of values. you may try reading it directly.

C#
    string xml = "<response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">"
                + "<errormessage />"
                + "<responsestatusmessage>521</responsestatusmessage>"
                + "<statusdescription> Description follows</statusdescription>"
                + "<number>4621</number>"
                + "<original>2122</original>"
                + "<dlmenabled />"
                + "<line>321</line>"
                + "</response>";
    TextReader reader=new StringReader(xml);
    XDocument xDoc = XDocument.Load(reader);
    Response res = new Response();
    res.errorMessage = xDoc.Descendants("ErrorMessage").FirstOrDefault().Value;
    res.responseStatusMessage =xDoc.Descendants("responseStatusMessage").FirstOrDefault().IsEmpty? Convert.ToInt32(xDoc.Descendants("responseStatusMessage").FirstOrDefault().Value):0;
    res.statusDescription = xDoc.Descendants("statusDescription").FirstOrDefault().Value;
    res.number =xDoc.Descendants("Number").FirstOrDefault().IsEmpty ?0:Convert.ToInt32(xDoc.Descendants("Number").FirstOrDefault().Value);
    res.original = xDoc.Descendants("original").FirstOrDefault().IsEmpty?0:Convert.ToInt32(xDoc.Descendants("original").FirstOrDefault().Value);
    res.dlmEnabled = xDoc.Descendants("dlmEnabled").FirstOrDefault().IsEmpty ?0: Convert.ToInt32(xDoc.Descendants("dlmEnabled").FirstOrDefault().Value) ;
    res.line = xDoc.Descendants("line").FirstOrDefault() .IsEmpty?0: Convert.ToInt32(xDoc.Descendants("line").FirstOrDefault().Value) ;


class Response
{
    public string errorMessage { get; set; }
    public int responseStatusMessage { get; set; }
    public string statusDescription { get; set; }
    public int number { get; set; }
    public int original { get; set; }
    public int dlmEnabled { get; set; }
    public int line { get; set; }

}
 
Share this answer
 
System.Xml.Linq.XElement xElemACFeedBackResp = null;

foreach (var command in taskCommands)
{

xElemACFeedBackResp = command.ACValue;
//AcValue means the XML
}
string status=string.empty;
status = xElemACFeedBackResp.Element("response").Value;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900