0

我有一些看起来像这样的 XML 文件:

<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
<s:ElementType name='row' content='eltOnly'>
    <s:AttributeType name='Idlog' rs:number='1'>
        <s:datatype dt:type='i2' dt:maxLength='2' rs:precision='5' rs:fixedlength='true' rs:maybenull='false'/>
    </s:AttributeType>
    <s:AttributeType name='ExpDate' rs:number='2' rs:writeunknown='true'>
        <s:datatype dt:type='dateTime' rs:dbtype='timestamp' dt:maxLength='16' rs:scale='0' rs:precision='16' rs:fixedlength='true'
         rs:maybenull='false'/>
    </s:AttributeType>
    <s:AttributeType name='ExpOper' rs:number='3' rs:writeunknown='true'>
        <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='30' rs:maybenull='false'/>
    </s:AttributeType>
    <s:AttributeType name='ImpDate' rs:number='4' rs:nullable='true' rs:writeunknown='true'>
        <s:datatype dt:type='dateTime' rs:dbtype='timestamp' dt:maxLength='16' rs:scale='0' rs:precision='16' rs:fixedlength='true'/>
    </s:AttributeType>
    <s:AttributeType name='ImpOper' rs:number='5' rs:nullable='true' rs:writeunknown='true'>
        <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='30'/>
    </s:AttributeType>
    <s:AttributeType name='MaxDate' rs:number='6' rs:nullable='true' rs:writeunknown='true'>
        <s:datatype dt:type='dateTime' rs:dbtype='timestamp' dt:maxLength='16' rs:scale='0' rs:precision='16' rs:fixedlength='true'/>
    </s:AttributeType>
    <s:AttributeType name='NameWS' rs:number='7' rs:writeunknown='true'>
        <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='20' rs:maybenull='false'/>
    </s:AttributeType>
    <s:extends type='rs:rowbase'/>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row Idlog='1123' ExpDate='2019-02-11T16:06:00' ExpOper='szf' MaxDate='2019-02-08T09:24:00' NameWS='КЦ-0'/>
</rs:data>
</xml>

我需要将类从 C# 代码导出到这个 XML 模式。我试图找到一些信息,并找到了 ADO DB 和 MSSQL 的示例。我没有 MSSQL 服务器。我试图导出 DataSet,但我得到了另一个模式。我需要来自示例的相同架构。有任何想法吗?

4

1 回答 1

2

您可以使用 DataSet 读取并将结果放入数据集中。数据在 datatable["row"] 中。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Data;

namespace ConsoleApplication1
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            DataSet ds = new DataSet();
            ds.ReadXml(FILENAME, XmlReadMode.Auto);
        }
 

    }
 
}
于 2020-09-29T15:49:23.173 回答