如何从一个数据集时,列数据是在XML本身获取XML数据? [英] How to Get the Xml Data from a DataSet when the column data is in xml itself?

查看:108
本文介绍了如何从一个数据集时,列数据是在XML本身获取XML数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储过程返回2 XML结果集如下:

I have a stored procedure which returns 2 xml resultsets as below:

SELECT 1 as SiteID
FOR XML PATH('FirstResultSet'), TYPE

SELECT 1 as UserID
FOR XML PATH('SecondResultSet'), TYPE

我遇到我的存储过程,并得到了DataSet对象。

I have run my stored procedure and got the DataSet object.

我叫的getXML方法,得到了XML:

I called the GetXml method and got the xml:

string xml = dataSet.GetXml();

但是XML是如下这是不期望格式:

But the xml is as below which is not in the expected format:

<NewDataSet>
<Table><Column1>&lt;FirstResultSet&gt;&lt;SiteID&gt;1&lt;SiteID&gt;&lt;FirstResultSet&gt;</Column1></Table>
<Table1><Column1>&lt;SecondResultSet&gt;&lt;UserID&gt;1&lt;UserID&gt;&lt;SecondResultSet&gt;</Column1></Table1>
</NewDataSet>

正如你所看到检索到的文本被视为文本而不是XML。

As you see the retrieved text is treated as text rather than xml.

如何获取XML列呢?我知道我可以只替换&LT;和>,但没有任何内置的方法,这使这更容易和更快更好的性能?

How to get the xml out of this? I know I can just replace "<" and ">" but is there any built-in method for this to make this easier and quicker with better performance?

string xml = dataSet.GetXml().Replace("&lt;", "<").Replace("&gt;", ">");

谢谢

推荐答案

尝试:

string xml = Server.HtmlDecode(dataSet.GetXml());

http://msdn.microsoft.com/en-us/library/ 7c5fyk1k.aspx

<打击>也许你需要完全相反的:

Maybe you need the exact opposite:

string xml = Server.HtmlEncode(dataSet.GetXml());

http://msdn.microsoft.com/en-us/library/ w3te6wfz.aspx

这篇关于如何从一个数据集时,列数据是在XML本身获取XML数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆