<?xml version="1.0" encoding="utf-8"?>
<MyRootClass xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<BusinessEvent Id="1" DisplayName="A Test Event" />
<Conditions>
<EventCondition Id="2" DisplayName="Condition 1">
<TheEvent href="1"/>
</EventCondition>
<EventCondition Id="3" DisplayName="Condition 2">
<TheEvent href="1"/>
</EventCondition>
</Conditions>
</MyRootClass>
<?xml version="1.0" encoding="utf-8"?>
<MyRootClass xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<BusinessEvent Id="1" DisplayName="A Test Event" />
<Conditions>
<EventCondition Id="2" DisplayName="Condition 1">
<TheEvent Id="1" DisplayName="A Test Event" />
</EventCondition>
<EventCondition Id="3" DisplayName="Condition 2">
<TheEvent Id="1" DisplayName="A Test Event" />
</EventCondition>
</Conditions>
</MyRootClass>
using System;
using System.Collections;
using System.IO;
using System.Xml.Serialization;
using System.Xml;
public class TestC {
public static void Main() {
TestC test = new TestC();
test.SerializeDocument("sharedEvent.xml");
}
public void SerializeDocument(string filename) {
XmlSerializer s = new XmlSerializer(typeof(MyRootClass));using (TextWriter writer= new StreamWriter(filename)) {
MyRootClass myRootClass = new MyRootClass();BusinessEvent evt = new BusinessEvent("1", "A Test Event");
myRootClass.TheSharedEvent = evt;EventCondition ec1 = new EventCondition("2", "Condition 1");
ec1.TheEvent = evt;
myRootClass.Conditions.Add(ec1);EventCondition ec2 = new EventCondition("3", "Condition 2");
ec2.TheEvent = evt;
myRootClass.Conditions.Add(ec2);
s.Serialize(writer, myRootClass);
}
}
}// This is the root class that will be serialized.
public class MyRootClass {
[XmlElement("BusinessEvent")]
public BusinessEvent TheSharedEvent;[XmlArrayItem(IsNullable=true, Type = typeof(EventCondition))]
[XmlArray]
public IList Conditions = new ArrayList();
}// A single instance of BusinessEvent will be shared by two EventCondition instances
public class BusinessEvent {
[XmlAttribute(DataType="ID")]
public string Id;[XmlAttribute]
public string DisplayName;public BusinessEvent() {}
public BusinessEvent(string Id, string DisplayName) {
this.Id = Id;
this.DisplayName = DisplayName;
}
}// Two EventCondition instances will refer to the same (single) BusinessEvent instance
public class EventCondition {
[XmlAttribute(DataType="ID")]
public string Id;[XmlAttribute]
public string DisplayName;//[XmlAttribute(DataType="IDREF")]
public BusinessEvent TheEvent;public EventCondition() {}
public EventCondition(string Id, string DisplayName) {
this.Id = Id;
this.DisplayName = DisplayName;
}
}
Anyways, once again, thanks for the tip.
Stuart."Christoph Schittko [MVP]" <christophdo...@austin.rr.com> wrote in message news:eJf7C8zS...@TK2MSFTNGP11.phx.gbl...
"Stuart Robertson" <sr_...@absolutesys.com> wrote in message news:O9aq6i3S...@TK2MSFTNGP12.phx.gbl...
that doesn't sound like an error that's happening just because of the SOAP style format. Any chance your output would not result in well-formed XML? Are you writing into a fresh, new, clean XmlTextWriter ?
using System;
using System.Collections;
using System.IO;
using System.Xml.Serialization;
using System.Xml;
public class TestD {
public static void Main() {
TestD test = new TestD();
test.SerializeUsingSoapFormatter("sharedEvent_SOAP.xml");
}
public void SerializeUsingSoapFormatter(string filename) {
XmlTextWriter writer = new XmlTextWriter(filename, null);
MyRootClass myRootClass = new MyRootClass();
BusinessEvent evt = new BusinessEvent("1", "A Test Event");
myRootClass.TheSharedEvent = evt;EventCondition ec1 = new EventCondition("2", "Condition 1");
ec1.TheEvent = evt;
myRootClass.Conditions.Add(ec1);EventCondition ec2 = new EventCondition("3", "Condition 2");
ec2.TheEvent = evt;
myRootClass.Conditions.Add(ec2);
XmlTypeMapping xmlTypeMapping = (new SoapReflectionImporter()).ImportTypeMapping(myRootClass.GetType());
XmlSerializer ser = new XmlSerializer(xmlTypeMapping);
ser.Serialize(writer, myRootClass);
}
}
// This is the root class that will be serialized.
public class MyRootClass {
[XmlElement("BusinessEvent")]
public BusinessEvent TheSharedEvent;[XmlArrayItem(IsNullable=true, Type = typeof(EventCondition))]
[XmlArray]
public IList Conditions = new ArrayList();
}
// An instance of BusinessEvent will be shared by two EventCondition instances
public class BusinessEvent {
public string Id;
[XmlAttribute]
public string DisplayName;public BusinessEvent() {}
public BusinessEvent(string Id, string DisplayName) {
this.Id = Id;
this.DisplayName = DisplayName;
}
}// Two EventCondition instances will refer to the same (single) BusinessEvent instance
public class EventCondition {
public string Id;[XmlAttribute]
public string DisplayName;
"Stuart Robertson" <sr_...@absolutesys.com> wrote in message news:O#Olo7CTD...@tk2msftngp13.phx.gbl...