【问题标题】:Loading xml file using asp.net return no records使用 asp.net 加载 xml 文件不返回任何记录
【发布时间】:2012-11-05 23:48:27
【问题描述】:

我有这个 XML 内容:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Option1>false</Option1>
  <Option2>http://www.google.com</Option2>
  <Option3>false</Option3>
  <Option4>false</Option4>
</configuration>

我尝试使用下面的代码来读取这个 xml,但 Dataset.tables.count 总是返回 0。

Dim dtConfig As New DataSet
Dim sArqXml as String = "asd.xml"

Dim xmlRoot As New XmlRootAttribute
xmlRoot.ElementName = "configuration"
xmlRoot.IsNullable = True

Dim xmlSer As XmlSerializer = New XmlSerializer(dtConfig.GetType, xmlRoot)
Dim fs As FileStream = New FileStream(sArqXml, FileMode.Open)

dtConfig = CType(xmlSer.Deserialize(fs), DataSet)
fs.Close()

如何阅读此 XML?解决方案可以在c#中。

【问题讨论】:

  • 是什么让您认为您可以将这些数据读入 DataSet?它是否来自来自数据集?

标签: asp.net xml vb.net


【解决方案1】:

将 xml 文件加载到数据集中。

    Imports System.Xml
    Dim ds As New DataSet
    ds.ReadXml("path_to_your_xml_file")

我认为在你的情况下应该是 ds.Table(0).Rows.Count

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多