gpt4 book ai didi

c# - 从数据库中解析xml

转载 作者:数据小太阳 更新时间:2023-10-29 01:53:45 24 4
gpt4 key购买 nike

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

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

目前我在 Datable 中返回结果。

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

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

billTo_lastName: asdf
orderAmount: 160.00
etc.

最佳答案

取决于你想如何处理它。一种方法是创建一个 XmlDocument 然后调用 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 :

var element = XElement.Load(dataString);

关于c# - 从数据库中解析xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15349517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com