G
Gasnic
Hi
I need to create a .NET object that will be serialized into the following xml structure ( I can't change the XML schema)
<Root>
<Record>
<Field1>data1</Field1>
<Field2>data2</Field2>
<Record>
<Record>
<Field1>data3</Field1>
<Field2>data4</Field2>
<Record>
</Root>
I tried to create a set of data class like this
Public Class Root
{
[XmlArray(ElementName="Record")]
[XmlArrayItem(Type=typeof(Record))]
public ArraryList Records;
}
Public Class Record
{
[XmlElement("Field1")]
public string Field1;
[XmlElement('Field2")]
public string Field2;
}
And inthe code I just create a serializer like the following and run the serialize method
XmlSerializer serializer = new XmlSerializer (typeof(Root));
serializer.serialize( myFileStream, myRootObj)
This way the serialized message become something like this
<Root xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Record>
<Record>
<Field1>data1</Field1>
<Field2>data2</Field2>
<Record>
<Record>
<Field1>data3</Field1>
<Field2>data4</Field2>
<Record>
<Record>
<Root>
Which is not what I want as it has an extra Record node outside the repeating Record node.
Anyone has idea how can I create a .NET object to serialize to the xml struct at the top?
Any help is greatly appericated
I need to create a .NET object that will be serialized into the following xml structure ( I can't change the XML schema)
<Root>
<Record>
<Field1>data1</Field1>
<Field2>data2</Field2>
<Record>
<Record>
<Field1>data3</Field1>
<Field2>data4</Field2>
<Record>
</Root>
I tried to create a set of data class like this
Public Class Root
{
[XmlArray(ElementName="Record")]
[XmlArrayItem(Type=typeof(Record))]
public ArraryList Records;
}
Public Class Record
{
[XmlElement("Field1")]
public string Field1;
[XmlElement('Field2")]
public string Field2;
}
And inthe code I just create a serializer like the following and run the serialize method
XmlSerializer serializer = new XmlSerializer (typeof(Root));
serializer.serialize( myFileStream, myRootObj)
This way the serialized message become something like this
<Root xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Record>
<Record>
<Field1>data1</Field1>
<Field2>data2</Field2>
<Record>
<Record>
<Field1>data3</Field1>
<Field2>data4</Field2>
<Record>
<Record>
<Root>
Which is not what I want as it has an extra Record node outside the repeating Record node.
Anyone has idea how can I create a .NET object to serialize to the xml struct at the top?
Any help is greatly appericated