0

I have some XML files which look like that:

<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>

I need to export classes from C# code to this XML schema. I tried to find some information and found examples with ADO DB and MSSQL. I don't have MSSQL server. I tried to export DataSet, but I got another schema. I need identical schema from example. Any ideas?

Noisy88
  • 181
  • 1
  • 14
  • ADODB is a 1990s-early 2000s technology. That's the reason you don't find a lot of information online. This particular way of generating XML data actually precedes XML Schema. Why do you want to export to this particular format? – Panagiotis Kanavos Sep 29 '20 at 15:29
  • @PanagiotisKanavos legacy applications were written by VB + MSSQL. Our modern application must support those old applications. I don't want to use that schema, I know this is a bad idea, but I must use it. – Noisy88 Sep 29 '20 at 15:38

1 Answers1

2

You can read with DataSet and put results into dataset. The data is in 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);
        }
 

    }
 
}
jdweng
  • 33,250
  • 2
  • 15
  • 20
  • Great. But what about the WriteXml method? I tried to use "WriteXml", but the schema was wrong. That file has a different schema-tag. – Noisy88 Sep 29 '20 at 16:34
  • Is schema wrong or just different? Did you include schema? : ds.WriteXml(FILENAME, XmlWriteMode.WriteSchema); – jdweng Sep 29 '20 at 16:49
  • Of course, I did. It had different schema tags and namespaces. I suppose that the old application won't be able to process this XML file. The schema must be identical to that one. – Noisy88 Sep 29 '20 at 18:18
  • I only see the default namespace being different and the order of the attributes. Does it make the difference the order of the attributes? – jdweng Sep 29 '20 at 19:54
  • I'm going to try using that XML file. Will see what happens. – Noisy88 Sep 30 '20 at 06:00