使用SP将XML转换为LINQ [英] XML to LINQ using SP
本文介绍了使用SP将XML转换为LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个存储过程正在返回XML文件.通过使用Linq,我想显示结果.我来自存储过程的XML文件就是这样....
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....
<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>
通过编写LINQ语句,我想显示以上值.你能帮我吗
问候,
S.Inayat Basha
By writting an LINQ statement i want to display the above values. Can you please help me
Regards,
S.Inayat Basha
推荐答案
嗨
我猜您不是要查询任何重复值或任何条件.只是一组值.您可以尝试直接阅读.
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.
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; }
}
System.Xml.Linq.XElement xElemACFeedBackResp = null;
foreach(taskCommands中的var命令)
{
xElemACFeedBackResp = command.ACValue;
//AcValue表示XML
}
字符串status = string.empty;
status = xElemACFeedBackResp.Element("response").Value;
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;
这篇关于使用SP将XML转换为LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文