从数据库解析xml [英] Parse xml from database

查看:37
本文介绍了从数据库解析xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我将 xml 存储在 ms sql 数据库中,不是文件.这是一个小样本.

Currently I have xml stored in a ms sql dbase and not a file. Here's a small sample.

<NewDataSet>
<Table1>
<billTo_lastName>asdf</billTo_lastName>
<orderAmount>160.00</orderAmount>
<billTo_street1>asdf</billTo_street1>
<card_accountNumber>############1111</card_accountNumber>
</Table1>
</NewDataSet>

目前我正在Datable中返回结果.

Currently I'm returning the result in a Datable.

解析上述内容并将其显示在页面上的最佳方法是什么.页面显示仅供参考.不会对 xml 进行额外的处理.

What would be the best way to parse the above and display it on a page. The page display is just for informational review. No additional processing will be done to the xml.

我希望页面显示这些内容.

I would like the page to display something along these lines.

billTo_lastName: asdf
orderAmount: 160.00
etc.

推荐答案

取决于您想要如何处理它.一种方法是创建一个 XmlDocument,然后调用 LoadXml:

Depends on how you want to process it. One way is to create an XmlDocument and then call LoadXml:

// get the data from the data table, into a string.

// then create an XML document and load the string
var doc = new XmlDocument();
doc.LoadXml(dataString);

如果您想使用 Linq-to-Xml,您需要创建一个 XElement:

If you want to use Linq-to-Xml, you'd create an XElement:

var element = XElement.Load(dataString);

这篇关于从数据库解析xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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