0

this is my xml file

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="Table1">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="MA_ID" type="xs:string" minOccurs="0" />
                <xs:element name="MA_CODE" type="xs:string" minOccurs="0" />
                <xs:element name="MA_CODE_P" type="xs:string" minOccurs="0" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <Table1>
    <MA_ID />
    <MA_CODE>PA15TX0009707</MA_CODE>
    <MA_CODE_P>PA15TX0009707001</MA_CODE_P>
  </Table1>
  <Table1>
    <MA_ID />
    <MA_CODE>PA15TX0009707</MA_CODE>
    <MA_CODE_P>PA15TX0009707001</MA_CODE_P>
  </Table1>
  <Table1>
    <MA_ID />
    <MA_CODE>PA15TX0009707</MA_CODE>
    <MA_CODE_P>PA15TX0009707001</MA_CODE_P>
  </Table1>
</NewDataSet>

After using the "Paste special" tool in VS, I have the following class

[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class NewDataSet
{

    private NewDataSetTable1[] table1Field;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("Table1")]
    public NewDataSetTable1[] Table1
    {
        get
        {
            return this.table1Field;
        }
        set
        {
            this.table1Field = value;
        }
    }
}

/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class NewDataSetTable1
{

    private object mA_IDField;

    private string mA_CODEField;

    private string mA_CODE_PField;

    /// <remarks/>
    public object MA_ID
    {
        get
        {
            return this.mA_IDField;
        }
        set
        {
            this.mA_IDField = value;
        }
    }

    /// <remarks/>
    public string MA_CODE
    {
        get
        {
            return this.mA_CODEField;
        }
        set
        {
            this.mA_CODEField = value;
        }
    }

    /// <remarks/>
    public string MA_CODE_P
    {
        get
        {
            return this.mA_CODE_PField;
        }
        set
        {
            this.mA_CODE_PField = value;
        }
    }
}

Then i use this class to work: converting xml files out to list objects, calc and replacing data ... and now i need to convert again from the list objects back to xml string, i use XmlSerializer But the return string missing the xs:schema section, so how can I convert the list to correct xml original format ?

jimbo R
  • 253
  • 2
  • 3
  • 14
  • It looks like that is actually a serialized [`DataSet`](https://msdn.microsoft.com/en-us/library/system.data.dataset(v=vs.110).aspx). If you deserialize and re-serialize it as such the schema should get preserved. Or you could keep the schema in an `[XmlAnyElement] public XmlElement[] Unsupported` property as shown in [XmlSerializer: keep unknown elements](https://stackoverflow.com/a/34788431/3744182). – dbc Apr 18 '18 at 17:20
  • Why do the title and tags of your question mention JSON? The body of your question has nothing to do with JSON. – dbc Apr 18 '18 at 17:21

0 Answers0