XmlSerializer and shared objects (or How to generate IDREFs using XmlSerializer)

This is a multi-part message in MIME format.

------=_NextPart_000_007F_01C34AC1.11D4FB20
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am trying to find a solution that will allow me to use XmlSerializer =
to serialize/deserialize a collection of objects where a given object is =
shared between two or more other objects, and not create duplicate XML =
representations of the shared object, but instead use IDREFs to refer to =
the shared object.

The XML I'm trying to produce is as follows (where "href" is an IDREF):
  <?xml version=3D"1.0" encoding=3D"utf-8"?>
  <MyRootClass xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema" =
xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance">
    <BusinessEvent Id=3D"1" DisplayName=3D"A Test Event" />
    <Conditions>
      <EventCondition Id=3D"2" DisplayName=3D"Condition 1">
        <TheEvent href=3D"1"/>
      </EventCondition>
      <EventCondition Id=3D"3" DisplayName=3D"Condition 2">
        <TheEvent href=3D"1"/>
      </EventCondition>
    </Conditions>
  </MyRootClass>
However, the XML produced by XmlSerializer is the following:
  <?xml version=3D"1.0" encoding=3D"utf-8"?>
  <MyRootClass xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema" =
xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance">
    <BusinessEvent Id=3D"1" DisplayName=3D"A Test Event" />
    <Conditions>
      <EventCondition Id=3D"2" DisplayName=3D"Condition 1">
        <TheEvent Id=3D"1" DisplayName=3D"A Test Event" />
      </EventCondition>
      <EventCondition Id=3D"3" DisplayName=3D"Condition 2">
        <TheEvent Id=3D"1" DisplayName=3D"A Test Event" />
      </EventCondition>
    </Conditions>
  </MyRootClass>
The code used to produce the (incorrect) XML is as follows:
  using System;
  using System.Collections;
  using System.IO;
  using System.Xml.Serialization;
  using System.Xml;
  =20
  public class TestC {
     public static void Main() {
        TestC test =3D new TestC();
        test.SerializeDocument("sharedEvent.xml");
     }
  =20
     public void SerializeDocument(string filename) {
        XmlSerializer s =3D new XmlSerializer(typeof(MyRootClass));

        using (TextWriter writer=3D new StreamWriter(filename)) {
           MyRootClass myRootClass =3D new MyRootClass();

           BusinessEvent evt =3D new BusinessEvent("1", "A Test Event");
           myRootClass.TheSharedEvent =3D evt;

           EventCondition ec1 =3D new EventCondition("2", "Condition =
1");
           ec1.TheEvent =3D evt;
           myRootClass.Conditions.Add(ec1);

           EventCondition ec2 =3D new EventCondition("3", "Condition =
2");
           ec2.TheEvent =3D evt;
           myRootClass.Conditions.Add(ec2);
  =20
           s.Serialize(writer, myRootClass);
        }
     }
  }

  // This is the root class that will be serialized.
  public class MyRootClass {
     [XmlElement("BusinessEvent")]
     public BusinessEvent TheSharedEvent;

     [XmlArrayItem(IsNullable=3Dtrue, Type =3D typeof(EventCondition))]
     [XmlArray]
     public IList Conditions =3D new ArrayList();
  }

  // A single instance of BusinessEvent will be shared by two =
EventCondition instances
  public class BusinessEvent {
     [XmlAttribute(DataType=3D"ID")]
     public string Id;

     [XmlAttribute]
     public string DisplayName;

     public BusinessEvent() {}
     public BusinessEvent(string Id, string DisplayName) {
        this.Id =3D Id;
        this.DisplayName =3D DisplayName;
     }
  }

  // Two EventCondition instances will refer to the same (single) =
BusinessEvent instance
  public class EventCondition {
     [XmlAttribute(DataType=3D"ID")]
     public string Id;

     [XmlAttribute]
     public string DisplayName;

     //[XmlAttribute(DataType=3D"IDREF")]
     public BusinessEvent TheEvent;

     public EventCondition() {}
     public EventCondition(string Id, string DisplayName) {
        this.Id =3D Id;
        this.DisplayName =3D DisplayName;
     }
  }

Any ideas or pointers on how to achieve the IDREF bit will be greatly =
appreciated.
------=_NextPart_000_007F_01C34AC1.11D4FB20
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>I am trying to find a solution that =
will allow me=20
to use XmlSerializer to serialize/deserialize a collection of objects =
where a=20
given object is shared between two or more other objects, and not create =

duplicate XML representations of the shared object, but instead use =
IDREFs to=20
refer to the shared object.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The XML I'm trying to produce is as =
follows (where=20
"href" is an IDREF):</FONT></DIV>
<BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">
  <DIV><SPAN class=3Db><FONT face=3DArial size=3D2>&lt;?xml =
version=3D"1.0"=20
  encoding=3D"utf-8"?&gt;<BR>&lt;MyRootClass xmlns:xsd=3D"</FONT><A=20
  href=3D"http://www.w3.org/2001/XMLSchema"><FONT face=3DArial=20
  size=3D2>http://www.w3.org/2001/XMLSchema</FONT></A><FONT face=3DArial =
size=3D2>"=20
  xmlns:xsi=3D"</FONT><A =
href=3D"http://www.w3.org/2001/XMLSchema-instance"><FONT=20
  face=3DArial =
size=3D2>http://www.w3.org/2001/XMLSchema-instance</FONT></A><FONT=20
  face=3DArial size=3D2>"&gt;<BR><STRONG>&nbsp; &lt;BusinessEvent =
Id=3D"1"=20
  DisplayName=3D"A Test Event" /&gt;<BR></STRONG>&nbsp;=20
  &lt;Conditions&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;EventCondition Id=3D"2"=20
  DisplayName=3D"Condition =
1"&gt;<BR><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  &lt;TheEvent href=3D"1"/&gt;<BR></STRONG>&nbsp;&nbsp;&nbsp;=20
  &lt;/EventCondition&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;EventCondition =
Id=3D"3"=20
  DisplayName=3D"Condition =
2"&gt;<BR><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  &lt;TheEvent href=3D"1"/&gt;<BR></STRONG>&nbsp;&nbsp;&nbsp;=20
  &lt;/EventCondition&gt;<BR>&nbsp;=20
  =
&lt;/Conditions&gt;<BR>&lt;/MyRootClass&gt;</FONT></SPAN></DIV></BLOCKQUO=
TE>
<DIV class=3De>
<DIV><SPAN class=3Dm><FONT face=3DArial size=3D2>However, the XML =
produced by=20
XmlSerializer is the following:</FONT></SPAN></DIV>
<BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">
  <DIV><SPAN class=3Dm><FONT face=3DArial size=3D2>&lt;?xml =
version=3D"1.0"=20
  encoding=3D"utf-8"?&gt;<BR>&lt;MyRootClass xmlns:xsd=3D"</FONT><A=20
  href=3D"http://www.w3.org/2001/XMLSchema"><FONT face=3DArial=20
  size=3D2>http://www.w3.org/2001/XMLSchema</FONT></A><FONT face=3DArial =
size=3D2>"=20
  xmlns:xsi=3D"</FONT><A =
href=3D"http://www.w3.org/2001/XMLSchema-instance"><FONT=20
  face=3DArial =
size=3D2>http://www.w3.org/2001/XMLSchema-instance</FONT></A><FONT=20
  face=3DArial size=3D2>"&gt;<BR><STRONG>&nbsp; &lt;BusinessEvent =
Id=3D"1"=20
  DisplayName=3D"A Test Event" /&gt;<BR></STRONG>&nbsp;=20
  &lt;Conditions&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;EventCondition Id=3D"2"=20
  DisplayName=3D"Condition =
1"&gt;<BR><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  &lt;TheEvent Id=3D"1" DisplayName=3D"A Test Event"=20
  /&gt;<BR></STRONG>&nbsp;&nbsp;&nbsp;=20
  &lt;/EventCondition&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;EventCondition =
Id=3D"3"=20
  DisplayName=3D"Condition =
2"&gt;<BR><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  &lt;TheEvent Id=3D"1" DisplayName=3D"A Test Event"=20
  /&gt;<BR></STRONG>&nbsp;&nbsp;&nbsp; &lt;/EventCondition&gt;<BR>&nbsp; =

  =
&lt;/Conditions&gt;<BR>&lt;/MyRootClass&gt;</FONT></SPAN></DIV></BLOCKQUO=
TE>
<DIV><SPAN class=3Dm><FONT face=3DArial size=3D2>The code used to =
produce the=20
(incorrect) XML is as follows:</FONT></SPAN></DIV>
<BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">
  <DIV><SPAN class=3Dm><FONT face=3DArial size=3D2>using =
System;<BR>using=20
  System.Collections;<BR>using System.IO;<BR>using=20
  System.Xml.Serialization;<BR>using System.Xml;<BR>&nbsp;<BR>public =
class TestC=20
  {<BR>&nbsp;&nbsp; public static void Main()=20
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TestC test =3D new=20
  TestC();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  test.SerializeDocument("sharedEvent.xml");<BR>&nbsp;&nbsp;=20
  }<BR>&nbsp;<BR>&nbsp;&nbsp; public void SerializeDocument(string =
filename)=20
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XmlSerializer s =3D new=20
  XmlSerializer(typeof(MyRootClass));</FONT></SPAN></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><SPAN class=3Dm><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  using (TextWriter writer=3D new StreamWriter(filename))=20
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MyRootClass =
myRootClass=20
  =3D new MyRootClass();</FONT></SPAN></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><SPAN class=3Dm><FONT face=3DArial=20
  size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
BusinessEvent evt =3D=20
  new BusinessEvent("1", "A Test=20
  Event");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  myRootClass.TheSharedEvent =3D evt;</FONT></SPAN></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><SPAN class=3Dm><FONT face=3DArial=20
  size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
EventCondition ec1 =3D=20
  new EventCondition("2", "Condition=20
  1");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ec1.TheEvent =
=3D=20
  evt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  myRootClass.Conditions.Add(ec1);</FONT></SPAN></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><SPAN class=3Dm><FONT face=3DArial=20
  size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
EventCondition ec2 =3D=20
  new EventCondition("3", "Condition=20
  2");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ec2.TheEvent =
=3D=20
  evt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  =
myRootClass.Conditions.Add(ec2);<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;=20
  s.Serialize(writer, myRootClass);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  }<BR>&nbsp;&nbsp; }<BR>}</FONT></SPAN></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><SPAN class=3Dm><FONT face=3DArial size=3D2>// This is the root =
class that will=20
  be serialized.<BR>public class MyRootClass {<BR>&nbsp;&nbsp;=20
  [XmlElement("BusinessEvent")]<BR>&nbsp;&nbsp; public BusinessEvent=20
  TheSharedEvent;</FONT></SPAN></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><SPAN class=3Dm><FONT face=3DArial size=3D2>&nbsp;&nbsp;=20
  [XmlArrayItem(IsNullable=3Dtrue, Type =3D =
typeof(EventCondition))]<BR>&nbsp;&nbsp;=20
  [XmlArray]<BR>&nbsp;&nbsp; public IList Conditions =3D new=20
  ArrayList();<BR>}</FONT></SPAN></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><SPAN class=3Dm><FONT face=3DArial size=3D2>// A single instance =
of=20
  BusinessEvent will be shared by two EventCondition instances<BR>public =
class=20
  BusinessEvent {<BR>&nbsp;&nbsp; =
[XmlAttribute(DataType=3D"ID")]<BR>&nbsp;&nbsp;=20
  public string Id;</FONT></SPAN></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><SPAN class=3Dm><FONT face=3DArial size=3D2>&nbsp;&nbsp;=20
  [XmlAttribute]<BR>&nbsp;&nbsp; public string =
DisplayName;</FONT></SPAN></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><SPAN class=3Dm><FONT face=3DArial size=3D2>&nbsp;&nbsp; public =
BusinessEvent()=20
  {}<BR>&nbsp;&nbsp; public BusinessEvent(string Id, string DisplayName) =

  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Id =3D=20
  Id;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.DisplayName =3D=20
  DisplayName;<BR>&nbsp;&nbsp; }<BR>}</FONT></SPAN></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><SPAN class=3Dm><FONT face=3DArial size=3D2>// Two EventCondition =
instances=20
  will refer to the same (single) BusinessEvent instance<BR>public class =

  EventCondition {<BR>&nbsp;&nbsp; =
[XmlAttribute(DataType=3D"ID")]<BR>&nbsp;&nbsp;=20
  public string Id;</FONT></SPAN></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><SPAN class=3Dm><FONT face=3DArial size=3D2>&nbsp;&nbsp;=20
  [XmlAttribute]<BR>&nbsp;&nbsp; public string =
DisplayName;</FONT></SPAN></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><SPAN class=3Dm><FONT face=3DArial size=3D2>&nbsp;&nbsp;=20
  //[XmlAttribute(DataType=3D"IDREF")]<BR>&nbsp;&nbsp; public =
BusinessEvent=20
  TheEvent;</FONT></SPAN></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><SPAN class=3Dm><FONT face=3DArial size=3D2>&nbsp;&nbsp; public=20
  EventCondition() {}<BR>&nbsp;&nbsp; public EventCondition(string Id, =
string=20
  DisplayName) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Id =3D=20
  Id;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.DisplayName =3D=20
  DisplayName;<BR>&nbsp;&nbsp; }<BR>}</FONT></SPAN></DIV>
  <DIV>&nbsp;</DIV></BLOCKQUOTE><SPAN class=3Dm><FONT face=3DArial =
size=3D2>
<DIV>Any ideas or pointers on how to achieve the IDREF bit will be =
greatly=20
appreciated.</DIV></FONT></SPAN></DIV></BODY></HTML>

------=_NextPart_000_007F_01C34AC1.11D4FB20--

0
sr_spam (4)
7/15/2003 9:05:58 AM
dotnet.xml 7266 articles. 0 followers. Follow

5 Replies
1122 Views

Similar Articles

[PageSpeed] 49

This is a multi-part message in MIME format.

------=_NextPart_000_014C_01C34B89.7C26B4A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi Christoph,

Thanks for the info.  Unfortunately, I can't get the code you suggested =
to work.  I get an InvalidOperationException that states:

Unhandled Exception: System.InvalidOperationException: There was an =
error generating the XML document. ---> =
System.InvalidOperationException:  Token StartElement in state Epilog =
would result in an invalid XML document.

So I guess I need to implement a full XML persistence framework =
myself.... :-(=20

I would have liked to have been able to extend XmlSerializer and =
XmlSerializationWriter, however there is no documentation for these =
things... MSDN simply states "This type supports the .NET Framework =
infrastructure and is not intended to be used directly from your code."  =
Alas. =20

<MildRant>
One wonders why Microsoft has made so many of the .NET Framework classes =
sealed, or declared so many methods as non-virtual, preventing extension =
and adaptation...?  Now I need to create duplicate much of the =
reflection work that XmlSerializer performs so that my XmlSerializer can =
use the same Xml attributes, etc. but correctly handle serialization of =
object graphs.
</MildRant>
Anyways, once again, thanks for the tip.Stuart."Christoph Schittko =
[MVP]" <christophdotnetINVALID@austin.rr.com> wrote in message =
news:eJf7C8zSDHA.2084@TK2MSFTNGP11.phx.gbl...
  Stuart,

  You can get the XmlSerializer to produce a format that's based on =
section 5 of the SOAP 1.1 spec [0]. However, that format serializes ALL =
objects in an object graph as top level objects and links them up via =
ID/IDREF combinations.

  To force that format you have to initialize the XmlSerializer with =
TypeMappings from the SoapReflectionImporter as shown in the snippet =
below:

  XmlTextWriter xw =3D new XmlTextWriter( "bla.xml", null );
  XmlSerializer ser =3D new XmlSerializer(xmlType);
  XmlTypeMapping xmlType =3D=20
    (new SoapReflectionImporter()).ImportTypeMapping(obj.GetType());
     ser.Serialize(xw, obj);

  If that's not good enough for you then you pretty much have to =
implement serialization by hand.

  --=20
  HTH
  Christoph Schittko [MVP]
  Software Architect, .NET Mentor

  "Stuart Robertson" <sr_spam@absolutesys.com> wrote in message =
news:OX$VQBrSDHA.3132@tk2msftngp13.phx.gbl...
  I am trying to find a solution that will allow me to use XmlSerializer =
to serialize/deserialize a collection of objects where a given object is =
shared between two or more other objects, and not create duplicate XML =
representations of the shared object, but instead use IDREFs to refer to =
the shared object.

  The XML I'm trying to produce is as follows (where "href" is an =
IDREF):
  <?xml version=3D"1.0" encoding=3D"utf-8"?>
  <MyRootClass xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema" =
xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance">
    <BusinessEvent Id=3D"1" DisplayName=3D"A Test Event" />
    <Conditions>
      <EventCondition Id=3D"2" DisplayName=3D"Condition 1">
        <TheEvent href=3D"1"/>
      </EventCondition>
      <EventCondition Id=3D"3" DisplayName=3D"Condition 2">
        <TheEvent href=3D"1"/>
      </EventCondition>
    </Conditions>
  </MyRootClass>
  However, the XML produced by XmlSerializer is the following:
  <?xml version=3D"1.0" encoding=3D"utf-8"?>
  <MyRootClass xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema" =
xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance">
    <BusinessEvent Id=3D"1" DisplayName=3D"A Test Event" />
    <Conditions>
      <EventCondition Id=3D"2" DisplayName=3D"Condition 1">
        <TheEvent Id=3D"1" DisplayName=3D"A Test Event" />
      </EventCondition>
      <EventCondition Id=3D"3" DisplayName=3D"Condition 2">
        <TheEvent Id=3D"1" DisplayName=3D"A Test Event" />
      </EventCondition>
    </Conditions>
  </MyRootClass>
  The code used to produce the (incorrect) XML is as follows:
  using System;
  using System.Collections;
  using System.IO;
  using System.Xml.Serialization;
  using System.Xml;
  =20
  public class TestC {
     public static void Main() {
        TestC test =3D new TestC();
        test.SerializeDocument("sharedEvent.xml");
     }
  =20
     public void SerializeDocument(string filename) {
        XmlSerializer s =3D new XmlSerializer(typeof(MyRootClass));

        using (TextWriter writer=3D new StreamWriter(filename)) {
           MyRootClass myRootClass =3D new MyRootClass();

           BusinessEvent evt =3D new BusinessEvent("1", "A Test Event");
           myRootClass.TheSharedEvent =3D evt;

           EventCondition ec1 =3D new EventCondition("2", "Condition =
1");
           ec1.TheEvent =3D evt;
           myRootClass.Conditions.Add(ec1);

           EventCondition ec2 =3D new EventCondition("3", "Condition =
2");
           ec2.TheEvent =3D evt;
           myRootClass.Conditions.Add(ec2);
  =20
           s.Serialize(writer, myRootClass);
        }
     }
  }

  // This is the root class that will be serialized.
  public class MyRootClass {
     [XmlElement("BusinessEvent")]
     public BusinessEvent TheSharedEvent;

     [XmlArrayItem(IsNullable=3Dtrue, Type =3D typeof(EventCondition))]
     [XmlArray]
     public IList Conditions =3D new ArrayList();
  }

  // A single instance of BusinessEvent will be shared by two =
EventCondition instances
  public class BusinessEvent {
     [XmlAttribute(DataType=3D"ID")]
     public string Id;

     [XmlAttribute]
     public string DisplayName;

     public BusinessEvent() {}
     public BusinessEvent(string Id, string DisplayName) {
        this.Id =3D Id;
        this.DisplayName =3D DisplayName;
     }
  }

  // Two EventCondition instances will refer to the same (single) =
BusinessEvent instance
  public class EventCondition {
     [XmlAttribute(DataType=3D"ID")]
     public string Id;

     [XmlAttribute]
     public string DisplayName;

     //[XmlAttribute(DataType=3D"IDREF")]
     public BusinessEvent TheEvent;

     public EventCondition() {}
     public EventCondition(string Id, string DisplayName) {
        this.Id =3D Id;
        this.DisplayName =3D DisplayName;
     }
  }

  Any ideas or pointers on how to achieve the IDREF bit will be greatly =
appreciated.
------=_NextPart_000_014C_01C34B89.7C26B4A0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff background=3D"">
<DIV><FONT face=3DArial size=3D2>Hi Christoph,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks for the info.&nbsp; =
Unfortunately, I can't=20
get the code you suggested to work.&nbsp; I get an =
InvalidOperationException=20
that states:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><EM>Unhandled Exception:=20
System.InvalidOperationException: There was an error generating the XML=20
document. ---&gt; System.InvalidOperationException:&nbsp; Token =
StartElement in=20
state Epilog would result in an invalid XML document.</EM></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>So I guess I need to implement a full =
XML=20
persistence framework myself.... :-( </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I would have liked to have been able to =
extend=20
XmlSerializer and XmlSerializationWriter, however there is no =
documentation for=20
these things... MSDN simply states <EM>"This type supports the .NET =
Framework=20
infrastructure and is not intended to be used directly from your=20
code."</EM><FONT face=3DArial size=3D2></FONT>&nbsp; =
Alas.&nbsp;&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&lt;MildRant&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>One wonders why Microsoft has made so =
many of the=20
..NET Framework classes sealed, or declared so many methods as =
non-virtual,=20
preventing extension and adaptation...?&nbsp; Now I need to create =
duplicate=20
much of the reflection work that XmlSerializer performs so that my =
XmlSerializer=20
can use the same Xml attributes, etc. but correctly handle serialization =
of=20
object graphs.</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&lt;/MildRant&gt;</FONT><FONT></DIV><PRE class=3Dsyntax =
style=3D"DISPLAY: none"><FONT face=3DArial size=3D2>Anyways, once again, =
thanks for the tip.</FONT></PRE><PRE class=3Dsyntax style=3D"DISPLAY: =
none"><FONT face=3DArial size=3D2>Stuart.</FONT></PRE></FONT>"Christoph=20
Schittko [MVP]" &lt;<A=20
href=3D"mailto:christophdotnetINVALID@austin.rr.com">christophdotnetINVAL=
ID@austin.rr.com</A>&gt;=20
wrote in message <A=20
href=3D"news:eJf7C8zSDHA.2084@TK2MSFTNGP11.phx.gbl">news:eJf7C8zSDHA.2084=
@TK2MSFTNGP11.phx.gbl</A>...
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV><FONT face=3DArial size=3D2>Stuart,</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>You can get the XmlSerializer to =
produce a format=20
  that's based on section 5 of the SOAP 1.1 spec [0]. However, that =
format=20
  serializes ALL objects in an object graph as top level objects and =
links them=20
  up via ID/IDREF combinations.<BR><BR>To force that format you have to=20
  initialize the XmlSerializer with TypeMappings from the =
SoapReflectionImporter=20
  as shown in the snippet below:<BR><BR>XmlTextWriter xw =3D new =
XmlTextWriter(=20
  "bla.xml", null );<BR>XmlSerializer ser =3D new=20
  XmlSerializer(xmlType);<BR>XmlTypeMapping xmlType =3D <BR>&nbsp; (new=20
  =
SoapReflectionImporter()).ImportTypeMapping(obj.GetType());<BR>&nbsp;&nbs=
p;=20
  ser.Serialize(xw, obj);</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>If that's not good enough for you =
then you pretty=20
  much have to implement serialization by hand.</DIV>
  <DIV><BR>-- <BR>HTH<BR>Christoph Schittko [MVP]<BR>Software Architect, =
..NET=20
  Mentor</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2><BR>"Stuart Robertson"=20
  &lt;sr_spam@absolutesys.com&gt; wrote in message=20
  news:OX$VQBrSDHA.3132@tk2msftngp13.phx.gbl...<BR>I am trying to find a =

  solution that will allow me to use XmlSerializer to =
serialize/deserialize a=20
  collection of objects where a given object is shared between two or =
more other=20
  objects, and not create duplicate XML representations of the shared =
object,=20
  but instead use IDREFs to refer to the shared object.<BR><BR>The XML =
I'm=20
  trying to produce is as follows (where "href" is an =
IDREF):<BR>&lt;?xml=20
  version=3D"1.0" encoding=3D"utf-8"?&gt;<BR>&lt;MyRootClass=20
  xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema"=20
  xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance"&gt;<BR>&nbsp;=20
  &lt;BusinessEvent Id=3D"1" DisplayName=3D"A Test Event" =
/&gt;<BR>&nbsp;=20
  &lt;Conditions&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;EventCondition Id=3D"2"=20
  DisplayName=3D"Condition 1"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;TheEvent=20
  href=3D"1"/&gt;<BR>&nbsp;&nbsp;&nbsp;=20
  &lt;/EventCondition&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;EventCondition =
Id=3D"3"=20
  DisplayName=3D"Condition 2"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;TheEvent=20
  href=3D"1"/&gt;<BR>&nbsp;&nbsp;&nbsp; =
&lt;/EventCondition&gt;<BR>&nbsp;=20
  &lt;/Conditions&gt;<BR>&lt;/MyRootClass&gt;<BR>However, the XML =
produced by=20
  XmlSerializer is the following:<BR>&lt;?xml version=3D"1.0"=20
  encoding=3D"utf-8"?&gt;<BR>&lt;MyRootClass=20
  xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema"=20
  xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance"&gt;<BR>&nbsp;=20
  &lt;BusinessEvent Id=3D"1" DisplayName=3D"A Test Event" =
/&gt;<BR>&nbsp;=20
  &lt;Conditions&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;EventCondition Id=3D"2"=20
  DisplayName=3D"Condition 1"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;TheEvent=20
  Id=3D"1" DisplayName=3D"A Test Event" /&gt;<BR>&nbsp;&nbsp;&nbsp;=20
  &lt;/EventCondition&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;EventCondition =
Id=3D"3"=20
  DisplayName=3D"Condition 2"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;TheEvent=20
  Id=3D"1" DisplayName=3D"A Test Event" /&gt;<BR>&nbsp;&nbsp;&nbsp;=20
  &lt;/EventCondition&gt;<BR>&nbsp;=20
  &lt;/Conditions&gt;<BR>&lt;/MyRootClass&gt;<BR>The code used to =
produce the=20
  (incorrect) XML is as follows:<BR>using System;<BR>using=20
  System.Collections;<BR>using System.IO;<BR>using=20
  System.Xml.Serialization;<BR>using System.Xml;<BR>&nbsp;<BR>public =
class TestC=20
  {<BR>&nbsp;&nbsp; public static void Main()=20
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TestC test =3D new=20
  TestC();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  test.SerializeDocument("sharedEvent.xml");<BR>&nbsp;&nbsp;=20
  }<BR>&nbsp;<BR>&nbsp;&nbsp; public void SerializeDocument(string =
filename)=20
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XmlSerializer s =3D new=20
  =
XmlSerializer(typeof(MyRootClass));<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
=20
  using (TextWriter writer=3D new StreamWriter(filename))=20
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MyRootClass =
myRootClass=20
  =3D new =
MyRootClass();<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  BusinessEvent evt =3D new BusinessEvent("1", "A Test=20
  Event");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  myRootClass.TheSharedEvent =3D=20
  evt;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
EventCondition=20
  ec1 =3D new EventCondition("2", "Condition=20
  1");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ec1.TheEvent =
=3D=20
  evt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  =
myRootClass.Conditions.Add(ec1);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;=20
  EventCondition ec2 =3D new EventCondition("3", "Condition=20
  2");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ec2.TheEvent =
=3D=20
  evt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  =
myRootClass.Conditions.Add(ec2);<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;=20
  s.Serialize(writer, myRootClass);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  }<BR>&nbsp;&nbsp; }<BR>}<BR><BR>// This is the root class that will be =

  serialized.<BR>public class MyRootClass {<BR>&nbsp;&nbsp;=20
  [XmlElement("BusinessEvent")]<BR>&nbsp;&nbsp; public BusinessEvent=20
  TheSharedEvent;<BR><BR>&nbsp;&nbsp; [XmlArrayItem(IsNullable=3Dtrue, =
Type =3D=20
  typeof(EventCondition))]<BR>&nbsp;&nbsp; [XmlArray]<BR>&nbsp;&nbsp; =
public=20
  IList Conditions =3D new ArrayList();<BR>}<BR><BR>// A single instance =
of=20
  BusinessEvent will be shared by two EventCondition instances<BR>public =
class=20
  BusinessEvent {<BR>&nbsp;&nbsp; =
[XmlAttribute(DataType=3D"ID")]<BR>&nbsp;&nbsp;=20
  public string Id;<BR><BR>&nbsp;&nbsp; [XmlAttribute]<BR>&nbsp;&nbsp; =
public=20
  string DisplayName;<BR><BR>&nbsp;&nbsp; public BusinessEvent()=20
  {}<BR>&nbsp;&nbsp; public BusinessEvent(string Id, string DisplayName) =

  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Id =3D=20
  Id;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.DisplayName =3D=20
  DisplayName;<BR>&nbsp;&nbsp; }<BR>}<BR><BR>// Two EventCondition =
instances=20
  will refer to the same (single) BusinessEvent instance<BR>public class =

  EventCondition {<BR>&nbsp;&nbsp; =
[XmlAttribute(DataType=3D"ID")]<BR>&nbsp;&nbsp;=20
  public string Id;<BR><BR>&nbsp;&nbsp; [XmlAttribute]<BR>&nbsp;&nbsp; =
public=20
  string DisplayName;<BR><BR>&nbsp;&nbsp;=20
  //[XmlAttribute(DataType=3D"IDREF")]<BR>&nbsp;&nbsp; public =
BusinessEvent=20
  TheEvent;<BR><BR>&nbsp;&nbsp; public EventCondition() =
{}<BR>&nbsp;&nbsp;=20
  public EventCondition(string Id, string DisplayName)=20
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Id =3D=20
  Id;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.DisplayName =3D=20
  DisplayName;<BR>&nbsp;&nbsp; }<BR>}<BR><BR>Any ideas or pointers on =
how to=20
  achieve the IDREF bit will be greatly=20
appreciated.</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_014C_01C34B89.7C26B4A0--

0
sr_spam (4)
7/16/2003 9:00:36 AM
This is a multi-part message in MIME format.

------=_NextPart_000_0048_01C34BE2.63B84A60
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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

--=20
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor
  "Stuart Robertson" <sr_spam@absolutesys.com> wrote in message =
news:O9aq6i3SDHA.2152@TK2MSFTNGP12.phx.gbl...
  Hi Christoph,

  Thanks for the info.  Unfortunately, I can't get the code you =
suggested to work.  I get an InvalidOperationException that states:

  Unhandled Exception: System.InvalidOperationException: There was an =
error generating the XML document. ---> =
System.InvalidOperationException:  Token StartElement in state Epilog =
would result in an invalid XML document.

  So I guess I need to implement a full XML persistence framework =
myself.... :-(=20

  I would have liked to have been able to extend XmlSerializer and =
XmlSerializationWriter, however there is no documentation for these =
things... MSDN simply states "This type supports the .NET Framework =
infrastructure and is not intended to be used directly from your code."  =
Alas. =20

  <MildRant>
  One wonders why Microsoft has made so many of the .NET Framework =
classes sealed, or declared so many methods as non-virtual, preventing =
extension and adaptation...?  Now I need to create duplicate much of the =
reflection work that XmlSerializer performs so that my XmlSerializer can =
use the same Xml attributes, etc. but correctly handle serialization of =
object graphs.
  </MildRant>
Anyways, once again, thanks for the tip.Stuart."Christoph Schittko =
[MVP]" <christophdotnetINVALID@austin.rr.com> wrote in message =
news:eJf7C8zSDHA.2084@TK2MSFTNGP11.phx.gbl...=20
    Stuart,

    You can get the XmlSerializer to produce a format that's based on =
section 5 of the SOAP 1.1 spec [0]. However, that format serializes ALL =
objects in an object graph as top level objects and links them up via =
ID/IDREF combinations.

    To force that format you have to initialize the XmlSerializer with =
TypeMappings from the SoapReflectionImporter as shown in the snippet =
below:

    XmlTextWriter xw =3D new XmlTextWriter( "bla.xml", null );
    XmlSerializer ser =3D new XmlSerializer(xmlType);
    XmlTypeMapping xmlType =3D=20
      (new SoapReflectionImporter()).ImportTypeMapping(obj.GetType());
       ser.Serialize(xw, obj);

    If that's not good enough for you then you pretty much have to =
implement serialization by hand.

    --=20
    HTH
    Christoph Schittko [MVP]
    Software Architect, .NET Mentor

    "Stuart Robertson" <sr_spam@absolutesys.com> wrote in message =
news:OX$VQBrSDHA.3132@tk2msftngp13.phx.gbl...
    I am trying to find a solution that will allow me to use =
XmlSerializer to serialize/deserialize a collection of objects where a =
given object is shared between two or more other objects, and not create =
duplicate XML representations of the shared object, but instead use =
IDREFs to refer to the shared object.

    The XML I'm trying to produce is as follows (where "href" is an =
IDREF):
    <?xml version=3D"1.0" encoding=3D"utf-8"?>
    <MyRootClass xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema" =
xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance">
      <BusinessEvent Id=3D"1" DisplayName=3D"A Test Event" />
      <Conditions>
        <EventCondition Id=3D"2" DisplayName=3D"Condition 1">
          <TheEvent href=3D"1"/>
        </EventCondition>
        <EventCondition Id=3D"3" DisplayName=3D"Condition 2">
          <TheEvent href=3D"1"/>
        </EventCondition>
      </Conditions>
    </MyRootClass>
    However, the XML produced by XmlSerializer is the following:
    <?xml version=3D"1.0" encoding=3D"utf-8"?>
    <MyRootClass xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema" =
xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance">
      <BusinessEvent Id=3D"1" DisplayName=3D"A Test Event" />
      <Conditions>
        <EventCondition Id=3D"2" DisplayName=3D"Condition 1">
          <TheEvent Id=3D"1" DisplayName=3D"A Test Event" />
        </EventCondition>
        <EventCondition Id=3D"3" DisplayName=3D"Condition 2">
          <TheEvent Id=3D"1" DisplayName=3D"A Test Event" />
        </EventCondition>
      </Conditions>
    </MyRootClass>
    The code used to produce the (incorrect) XML is as follows:
    using System;
    using System.Collections;
    using System.IO;
    using System.Xml.Serialization;
    using System.Xml;
    =20
    public class TestC {
       public static void Main() {
          TestC test =3D new TestC();
          test.SerializeDocument("sharedEvent.xml");
       }
    =20
       public void SerializeDocument(string filename) {
          XmlSerializer s =3D new XmlSerializer(typeof(MyRootClass));

          using (TextWriter writer=3D new StreamWriter(filename)) {
             MyRootClass myRootClass =3D new MyRootClass();

             BusinessEvent evt =3D new BusinessEvent("1", "A Test =
Event");
             myRootClass.TheSharedEvent =3D evt;

             EventCondition ec1 =3D new EventCondition("2", "Condition =
1");
             ec1.TheEvent =3D evt;
             myRootClass.Conditions.Add(ec1);

             EventCondition ec2 =3D new EventCondition("3", "Condition =
2");
             ec2.TheEvent =3D evt;
             myRootClass.Conditions.Add(ec2);
    =20
             s.Serialize(writer, myRootClass);
          }
       }
    }

    // This is the root class that will be serialized.
    public class MyRootClass {
       [XmlElement("BusinessEvent")]
       public BusinessEvent TheSharedEvent;

       [XmlArrayItem(IsNullable=3Dtrue, Type =3D =
typeof(EventCondition))]
       [XmlArray]
       public IList Conditions =3D new ArrayList();
    }

    // A single instance of BusinessEvent will be shared by two =
EventCondition instances
    public class BusinessEvent {
       [XmlAttribute(DataType=3D"ID")]
       public string Id;

       [XmlAttribute]
       public string DisplayName;

       public BusinessEvent() {}
       public BusinessEvent(string Id, string DisplayName) {
          this.Id =3D Id;
          this.DisplayName =3D DisplayName;
       }
    }

    // Two EventCondition instances will refer to the same (single) =
BusinessEvent instance
    public class EventCondition {
       [XmlAttribute(DataType=3D"ID")]
       public string Id;

       [XmlAttribute]
       public string DisplayName;

       //[XmlAttribute(DataType=3D"IDREF")]
       public BusinessEvent TheEvent;

       public EventCondition() {}
       public EventCondition(string Id, string DisplayName) {
          this.Id =3D Id;
          this.DisplayName =3D DisplayName;
       }
    }

    Any ideas or pointers on how to achieve the IDREF bit will be =
greatly appreciated.
------=_NextPart_000_0048_01C34BE2.63B84A60
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.3790.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff background=3D"">
<DIV><FONT face=3DArial size=3D2>that doesn't sound like an error that's =
happening=20
just because of the SOAP style format. Any chance your output would not =
result=20
in well-formed XML? Are you writing into a fresh, new, clean =
XmlTextWriter=20
?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>-- <BR>HTH<BR>Christoph Schittko [MVP]<BR>Software Architect, .NET=20
Mentor</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV>"Stuart Robertson" &lt;<A=20
  =
href=3D"mailto:sr_spam@absolutesys.com">sr_spam@absolutesys.com</A>&gt; =
wrote in=20
  message <A=20
  =
href=3D"news:O9aq6i3SDHA.2152@TK2MSFTNGP12.phx.gbl">news:O9aq6i3SDHA.2152=
@TK2MSFTNGP12.phx.gbl</A>...</DIV>
  <DIV><FONT face=3DArial size=3D2>Hi Christoph,</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Thanks for the info.&nbsp; =
Unfortunately, I can't=20
  get the code you suggested to work.&nbsp; I get an =
InvalidOperationException=20
  that states:</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2><EM>Unhandled Exception:=20
  System.InvalidOperationException: There was an error generating the =
XML=20
  document. ---&gt; System.InvalidOperationException:&nbsp; Token =
StartElement=20
  in state Epilog would result in an invalid XML =
document.</EM></FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>So I guess I need to implement a full =
XML=20
  persistence framework myself.... :-( </FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>I would have liked to have been able =
to extend=20
  XmlSerializer and XmlSerializationWriter, however there is no =
documentation=20
  for these things... MSDN simply states <EM>"This type supports the =
..NET=20
  Framework infrastructure and is not intended to be used directly from =
your=20
  code."</EM><FONT face=3DArial size=3D2></FONT>&nbsp;=20
Alas.&nbsp;&nbsp;</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&lt;MildRant&gt;</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>One wonders why Microsoft has made so =
many of the=20
  .NET Framework classes sealed, or declared so many methods as =
non-virtual,=20
  preventing extension and adaptation...?&nbsp; Now I need to create =
duplicate=20
  much of the reflection work that XmlSerializer performs so that my=20
  XmlSerializer can use the same Xml attributes, etc. but correctly =
handle=20
  serialization of object graphs.</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&lt;/MildRant&gt;</FONT><FONT =
size=3D+0></DIV><PRE class=3Dsyntax style=3D"DISPLAY: none"><FONT =
face=3DArial size=3D2>Anyways, once again, thanks for the =
tip.</FONT></PRE><PRE class=3Dsyntax style=3D"DISPLAY: none"><FONT =
face=3DArial size=3D2>Stuart.</FONT></PRE></FONT>"Christoph=20
  Schittko [MVP]" &lt;<A=20
  =
href=3D"mailto:christophdotnetINVALID@austin.rr.com">christophdotnetINVAL=
ID@austin.rr.com</A>&gt;=20
  wrote in message <A=20
  =
href=3D"news:eJf7C8zSDHA.2084@TK2MSFTNGP11.phx.gbl">news:eJf7C8zSDHA.2084=
@TK2MSFTNGP11.phx.gbl</A>...=20

  <BLOCKQUOTE dir=3Dltr=20
  style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
    <DIV><FONT face=3DArial size=3D2>Stuart,</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT face=3DArial size=3D2>You can get the XmlSerializer to =
produce a=20
    format that's based on section 5 of the SOAP 1.1 spec [0]. However, =
that=20
    format serializes ALL objects in an object graph as top level =
objects and=20
    links them up via ID/IDREF combinations.<BR><BR>To force that format =
you=20
    have to initialize the XmlSerializer with TypeMappings from the=20
    SoapReflectionImporter as shown in the snippet =
below:<BR><BR>XmlTextWriter=20
    xw =3D new XmlTextWriter( "bla.xml", null );<BR>XmlSerializer ser =
=3D new=20
    XmlSerializer(xmlType);<BR>XmlTypeMapping xmlType =3D <BR>&nbsp; =
(new=20
    =
SoapReflectionImporter()).ImportTypeMapping(obj.GetType());<BR>&nbsp;&nbs=
p;=20
    ser.Serialize(xw, obj);</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT face=3DArial size=3D2>If that's not good enough for you =
then you=20
    pretty much have to implement serialization by hand.</DIV>
    <DIV><BR>-- <BR>HTH<BR>Christoph Schittko [MVP]<BR>Software =
Architect, .NET=20
    Mentor</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2><BR>"Stuart Robertson"=20
    &lt;sr_spam@absolutesys.com&gt; wrote in message=20
    news:OX$VQBrSDHA.3132@tk2msftngp13.phx.gbl...<BR>I am trying to find =
a=20
    solution that will allow me to use XmlSerializer to =
serialize/deserialize a=20
    collection of objects where a given object is shared between two or =
more=20
    other objects, and not create duplicate XML representations of the =
shared=20
    object, but instead use IDREFs to refer to the shared =
object.<BR><BR>The XML=20
    I'm trying to produce is as follows (where "href" is an =
IDREF):<BR>&lt;?xml=20
    version=3D"1.0" encoding=3D"utf-8"?&gt;<BR>&lt;MyRootClass=20
    xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema"=20
    =
xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance"&gt;<BR>&nbsp;=20
    &lt;BusinessEvent Id=3D"1" DisplayName=3D"A Test Event" =
/&gt;<BR>&nbsp;=20
    &lt;Conditions&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;EventCondition Id=3D"2" =

    DisplayName=3D"Condition 1"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;TheEvent=20
    href=3D"1"/&gt;<BR>&nbsp;&nbsp;&nbsp;=20
    &lt;/EventCondition&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;EventCondition =
Id=3D"3"=20
    DisplayName=3D"Condition 2"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;TheEvent=20
    href=3D"1"/&gt;<BR>&nbsp;&nbsp;&nbsp; =
&lt;/EventCondition&gt;<BR>&nbsp;=20
    &lt;/Conditions&gt;<BR>&lt;/MyRootClass&gt;<BR>However, the XML =
produced by=20
    XmlSerializer is the following:<BR>&lt;?xml version=3D"1.0"=20
    encoding=3D"utf-8"?&gt;<BR>&lt;MyRootClass=20
    xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema"=20
    =
xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance"&gt;<BR>&nbsp;=20
    &lt;BusinessEvent Id=3D"1" DisplayName=3D"A Test Event" =
/&gt;<BR>&nbsp;=20
    &lt;Conditions&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;EventCondition Id=3D"2" =

    DisplayName=3D"Condition 1"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;TheEvent=20
    Id=3D"1" DisplayName=3D"A Test Event" /&gt;<BR>&nbsp;&nbsp;&nbsp;=20
    &lt;/EventCondition&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;EventCondition =
Id=3D"3"=20
    DisplayName=3D"Condition 2"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;TheEvent=20
    Id=3D"1" DisplayName=3D"A Test Event" /&gt;<BR>&nbsp;&nbsp;&nbsp;=20
    &lt;/EventCondition&gt;<BR>&nbsp;=20
    &lt;/Conditions&gt;<BR>&lt;/MyRootClass&gt;<BR>The code used to =
produce the=20
    (incorrect) XML is as follows:<BR>using System;<BR>using=20
    System.Collections;<BR>using System.IO;<BR>using=20
    System.Xml.Serialization;<BR>using System.Xml;<BR>&nbsp;<BR>public =
class=20
    TestC {<BR>&nbsp;&nbsp; public static void Main()=20
    {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TestC test =3D new=20
    TestC();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    test.SerializeDocument("sharedEvent.xml");<BR>&nbsp;&nbsp;=20
    }<BR>&nbsp;<BR>&nbsp;&nbsp; public void SerializeDocument(string =
filename)=20
    {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XmlSerializer s =3D new=20
    =
XmlSerializer(typeof(MyRootClass));<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
=20
    using (TextWriter writer=3D new StreamWriter(filename))=20
    {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MyRootClass=20
    myRootClass =3D new=20
    =
MyRootClass();<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    BusinessEvent evt =3D new BusinessEvent("1", "A Test=20
    Event");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    myRootClass.TheSharedEvent =3D=20
    evt;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
EventCondition=20
    ec1 =3D new EventCondition("2", "Condition=20
    1");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
ec1.TheEvent =3D=20
    evt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    =
myRootClass.Conditions.Add(ec1);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;=20
    EventCondition ec2 =3D new EventCondition("3", "Condition=20
    2");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
ec2.TheEvent =3D=20
    evt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    =
myRootClass.Conditions.Add(ec2);<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;=20
    s.Serialize(writer, myRootClass);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    }<BR>&nbsp;&nbsp; }<BR>}<BR><BR>// This is the root class that will =
be=20
    serialized.<BR>public class MyRootClass {<BR>&nbsp;&nbsp;=20
    [XmlElement("BusinessEvent")]<BR>&nbsp;&nbsp; public BusinessEvent=20
    TheSharedEvent;<BR><BR>&nbsp;&nbsp; [XmlArrayItem(IsNullable=3Dtrue, =
Type =3D=20
    typeof(EventCondition))]<BR>&nbsp;&nbsp; [XmlArray]<BR>&nbsp;&nbsp; =
public=20
    IList Conditions =3D new ArrayList();<BR>}<BR><BR>// A single =
instance of=20
    BusinessEvent will be shared by two EventCondition =
instances<BR>public class=20
    BusinessEvent {<BR>&nbsp;&nbsp;=20
    [XmlAttribute(DataType=3D"ID")]<BR>&nbsp;&nbsp; public string=20
    Id;<BR><BR>&nbsp;&nbsp; [XmlAttribute]<BR>&nbsp;&nbsp; public string =

    DisplayName;<BR><BR>&nbsp;&nbsp; public BusinessEvent() =
{}<BR>&nbsp;&nbsp;=20
    public BusinessEvent(string Id, string DisplayName)=20
    {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Id =3D=20
    Id;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.DisplayName =3D=20
    DisplayName;<BR>&nbsp;&nbsp; }<BR>}<BR><BR>// Two EventCondition =
instances=20
    will refer to the same (single) BusinessEvent instance<BR>public =
class=20
    EventCondition {<BR>&nbsp;&nbsp;=20
    [XmlAttribute(DataType=3D"ID")]<BR>&nbsp;&nbsp; public string=20
    Id;<BR><BR>&nbsp;&nbsp; [XmlAttribute]<BR>&nbsp;&nbsp; public string =

    DisplayName;<BR><BR>&nbsp;&nbsp;=20
    //[XmlAttribute(DataType=3D"IDREF")]<BR>&nbsp;&nbsp; public =
BusinessEvent=20
    TheEvent;<BR><BR>&nbsp;&nbsp; public EventCondition() =
{}<BR>&nbsp;&nbsp;=20
    public EventCondition(string Id, string DisplayName)=20
    {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Id =3D=20
    Id;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.DisplayName =3D=20
    DisplayName;<BR>&nbsp;&nbsp; }<BR>}<BR><BR>Any ideas or pointers on =
how to=20
    achieve the IDREF bit will be greatly=20
appreciated.</FONT></DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0048_01C34BE2.63B84A60--

0
7/17/2003 2:37:00 AM
This is a multi-part message in MIME format.

------=_NextPart_000_0167_01C34C3F.A9FF5740
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Christoph,
  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 =
?
The code I'm using is shown below (and yes, I'm using a fresh, new, =
clean XmlTextWriter - see the bolded text).  I'm trying this using .NET =
Framework 1.1, but it fails in most situations.
  using System;
  using System.Collections;
  using System.IO;
  using System.Xml.Serialization;
  using System.Xml;
  =20
  public class TestD {
     public static void Main() {
        TestD test =3D new TestD();
         test.SerializeUsingSoapFormatter("sharedEvent_SOAP.xml");
     }
  =20
     public void SerializeUsingSoapFormatter(string filename) {
           XmlTextWriter writer =3D new XmlTextWriter(filename, null);
           MyRootClass myRootClass =3D new MyRootClass();

           BusinessEvent evt =3D new BusinessEvent("1", "A Test Event");
           myRootClass.TheSharedEvent =3D evt;

           EventCondition ec1 =3D new EventCondition("2", "Condition =
1");
           ec1.TheEvent =3D evt;
           myRootClass.Conditions.Add(ec1);

           EventCondition ec2 =3D new EventCondition("3", "Condition =
2");
           ec2.TheEvent =3D evt;
           myRootClass.Conditions.Add(ec2);

           XmlTypeMapping xmlTypeMapping =3D (new =
SoapReflectionImporter()).ImportTypeMapping(myRootClass.GetType());
           XmlSerializer ser =3D 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=3Dtrue, Type =3D typeof(EventCondition))]
     [XmlArray]
     public IList Conditions =3D 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 =3D Id;
        this.DisplayName =3D DisplayName;
     }
  }

  // Two EventCondition instances will refer to the same (single) =
BusinessEvent instance
  public class EventCondition {
     public string Id;
     [XmlAttribute]
     public string DisplayName;
     public BusinessEvent TheEvent;

     public EventCondition() {}
     public EventCondition(string Id, string DisplayName) {
        this.Id =3D Id;
        this.DisplayName =3D DisplayName;
     }
  }

------=_NextPart_000_0167_01C34C3F.A9FF5740
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff background=3D"">
<DIV><FONT face=3DArial size=3D2>Christoph,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV><FONT face=3DArial size=3D2>that doesn't sound like an error =
that's happening=20
  just because of the SOAP style format. Any chance your output would =
not result=20
  in well-formed XML? Are you writing into a fresh, new, clean =
XmlTextWriter=20
  ?</FONT></DIV></BLOCKQUOTE></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>The code I'm using is shown below (and =
yes, I'm=20
using a fresh, new, clean XmlTextWriter - see the bolded text).&nbsp; =
I'm trying=20
this using .NET Framework 1.1, but it fails in most =
situations.</FONT></DIV>
<BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">
  <DIV><FONT face=3DArial size=3D2>using System;<BR>using=20
  System.Collections;<BR>using System.IO;<BR>using=20
  System.Xml.Serialization;<BR>using System.Xml;<BR>&nbsp;<BR>public =
class TestD=20
  {<BR>&nbsp;&nbsp; public static void Main()=20
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TestD test =3D new =
TestD();<BR>&nbsp;=20
  &nbsp;&nbsp;&nbsp;&nbsp;=20
  =
test.SerializeUsingSoapFormatter("sharedEvent_SOAP.xml");<BR>&nbsp;&nbsp;=
=20
  }<BR>&nbsp;<BR></FONT><FONT face=3DArial size=3D2>&nbsp;&nbsp; public =
void=20
  SerializeUsingSoapFormatter(string filename)=20
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
<STRONG>XmlTextWriter=20
  writer =3D new XmlTextWriter(filename,=20
  null);<BR></STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  MyRootClass myRootClass =3D new MyRootClass();</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  BusinessEvent evt =3D new BusinessEvent("1", "A Test=20
  Event");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  myRootClass.TheSharedEvent =3D evt;</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  EventCondition ec1 =3D new EventCondition("2", "Condition=20
  1");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ec1.TheEvent =
=3D=20
  evt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  myRootClass.Conditions.Add(ec1);</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  EventCondition ec2 =3D new EventCondition("3", "Condition=20
  2");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ec2.TheEvent =
=3D=20
  evt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  myRootClass.Conditions.Add(ec2);</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  XmlTypeMapping xmlTypeMapping =3D (new=20
  =
SoapReflectionImporter()).ImportTypeMapping(myRootClass.GetType());<BR>&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  XmlSerializer ser =3D new=20
  =
XmlSerializer(xmlTypeMapping);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;=20
  ser.Serialize(<STRONG>writer</STRONG>, myRootClass);<BR>&nbsp;&nbsp;=20
  }<BR>}</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>// This is the root class that will =
be=20
  serialized.<BR>public class MyRootClass {<BR>&nbsp;&nbsp;=20
  [XmlElement("BusinessEvent")]<BR>&nbsp;&nbsp; public BusinessEvent=20
  TheSharedEvent;</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; =
[XmlArrayItem(IsNullable=3Dtrue, Type=20
  =3D typeof(EventCondition))]<BR>&nbsp;&nbsp; =
[XmlArray]<BR>&nbsp;&nbsp; public=20
  IList Conditions =3D new ArrayList();<BR>}</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>// An instance of BusinessEvent will =
be shared by=20
  two EventCondition instances<BR>public class BusinessEvent =
{<BR>&nbsp;&nbsp;=20
  public string Id;</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; =
[XmlAttribute]<BR>&nbsp;&nbsp;=20
  public string DisplayName;</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; public BusinessEvent()=20
  {}<BR>&nbsp;&nbsp; public BusinessEvent(string Id, string DisplayName) =

  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Id =3D=20
  Id;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.DisplayName =3D=20
  DisplayName;<BR>&nbsp;&nbsp; }<BR>}</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>// Two EventCondition instances will =
refer to the=20
  same (single) BusinessEvent instance<BR>public class EventCondition=20
  {<BR>&nbsp;&nbsp; public string Id;</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; =
[XmlAttribute]<BR>&nbsp;&nbsp;=20
  public string DisplayName;</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; public BusinessEvent=20
  TheEvent;</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; public EventCondition()=20
  {}<BR>&nbsp;&nbsp; public EventCondition(string Id, string =
DisplayName)=20
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Id =3D=20
  Id;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.DisplayName =3D=20
  DisplayName;<BR>&nbsp;&nbsp; }<BR>}</FONT></DIV></BLOCKQUOTE>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV><FONT face=3DArial =
size=3D2></FONT>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0167_01C34C3F.A9FF5740--

0
sr_spam (4)
7/17/2003 6:44:41 AM
This is a multi-part message in MIME format.

------=_NextPart_000_002C_01C34C68.A21B8C50
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Stuart,

I am sorry if I wasn't clear enough. The with the Soap 1.1 Section 5 =
encoding, EVERY object in the object graph will be serialized as a top =
level element, which does not result in well-formed XML unless you =
enclose the serialized output in a common element. If you don't write a =
common parent element the underlying XmlTextWriter will complain ( throw =
an exception ) when you are attempting to write a 2nd top level element.

Everything will work once you add a line like this

         XmlSerializer ser =3D new XmlSerializer(xmlTypeMapping);
         writer.WriteStartElement( "myCommonRoot" );
         ser.Serialize(writer, myRootClass);
         writer.WriteEndElement(); // myCommonRoot

and then manually skip over that element when you deserialize.

--=20
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor
  "Stuart Robertson" <sr_spam@absolutesys.com> wrote in message =
news:O#Olo7CTDHA.2228@tk2msftngp13.phx.gbl...
  Christoph,
    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 =
?
  The code I'm using is shown below (and yes, I'm using a fresh, new, =
clean XmlTextWriter - see the bolded text).  I'm trying this using .NET =
Framework 1.1, but it fails in most situations.
    using System;
    using System.Collections;
    using System.IO;
    using System.Xml.Serialization;
    using System.Xml;
    =20
    public class TestD {
       public static void Main() {
          TestD test =3D new TestD();
           test.SerializeUsingSoapFormatter("sharedEvent_SOAP.xml");
       }
    =20
       public void SerializeUsingSoapFormatter(string filename) {
             XmlTextWriter writer =3D new XmlTextWriter(filename, null);
             MyRootClass myRootClass =3D new MyRootClass();

             BusinessEvent evt =3D new BusinessEvent("1", "A Test =
Event");
             myRootClass.TheSharedEvent =3D evt;

             EventCondition ec1 =3D new EventCondition("2", "Condition =
1");
             ec1.TheEvent =3D evt;
             myRootClass.Conditions.Add(ec1);

             EventCondition ec2 =3D new EventCondition("3", "Condition =
2");
             ec2.TheEvent =3D evt;
             myRootClass.Conditions.Add(ec2);

             XmlTypeMapping xmlTypeMapping =3D (new =
SoapReflectionImporter()).ImportTypeMapping(myRootClass.GetType());
             XmlSerializer ser =3D 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=3Dtrue, Type =3D =
typeof(EventCondition))]
       [XmlArray]
       public IList Conditions =3D 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 =3D Id;
          this.DisplayName =3D DisplayName;
       }
    }

    // Two EventCondition instances will refer to the same (single) =
BusinessEvent instance
    public class EventCondition {
       public string Id;
       [XmlAttribute]
       public string DisplayName;
       public BusinessEvent TheEvent;

       public EventCondition() {}
       public EventCondition(string Id, string DisplayName) {
          this.Id =3D Id;
          this.DisplayName =3D DisplayName;
       }
    }

------=_NextPart_000_002C_01C34C68.A21B8C50
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.3790.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff background=3D"">
<DIV><FONT face=3DArial size=3D2>Stuart,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I am sorry if I wasn't clear enough. =
The with the=20
Soap 1.1 Section 5 encoding, EVERY object in the object graph will be =
serialized=20
as a top level element, which does not result in well-formed XML unless =
you=20
enclose the serialized output in a common element. If you don't write a =
common=20
parent element the underlying XmlTextWriter will complain ( throw an =
exception )=20
when you are attempting to write a 2nd top level element.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Everything will work once you add a =
line like=20
this</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT><FONT=20
face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
XmlSerializer ser =3D new XmlSerializer(xmlTypeMapping);</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
writer.WriteStartElement( "myCommonRoot"=20
);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
ser.Serialize(<STRONG>writer</STRONG>, myRootClass);</FONT><BR><FONT =
face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; =
writer.WriteEndElement(); //=20
myCommonRoot</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>and then manually skip over that =
element when you=20
deserialize.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><BR>-- <BR>HTH<BR>Christoph =
Schittko=20
[MVP]<BR>Software Architect, .NET Mentor</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV>"Stuart Robertson" &lt;<A=20
  =
href=3D"mailto:sr_spam@absolutesys.com">sr_spam@absolutesys.com</A>&gt; =
wrote in=20
  message <A=20
  =
href=3D"news:O#Olo7CTDHA.2228@tk2msftngp13.phx.gbl">news:O#Olo7CTDHA.2228=
@tk2msftngp13.phx.gbl</A>...</DIV>
  <DIV><FONT face=3DArial size=3D2>Christoph,</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>
  <BLOCKQUOTE dir=3Dltr=20
  style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
    <DIV><FONT face=3DArial size=3D2>that doesn't sound like an error =
that's=20
    happening just because of the SOAP style format. Any chance your =
output=20
    would not result in well-formed XML? Are you writing into a fresh, =
new,=20
    clean XmlTextWriter ?</FONT></DIV></BLOCKQUOTE></FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>The code I'm using is shown below =
(and yes, I'm=20
  using a fresh, new, clean XmlTextWriter - see the bolded text).&nbsp; =
I'm=20
  trying this using .NET Framework 1.1, but it fails in most=20
  situations.</FONT></DIV>
  <BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">
    <DIV><FONT face=3DArial size=3D2>using System;<BR>using=20
    System.Collections;<BR>using System.IO;<BR>using=20
    System.Xml.Serialization;<BR>using System.Xml;<BR>&nbsp;<BR>public =
class=20
    TestD {<BR>&nbsp;&nbsp; public static void Main()=20
    {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TestD test =3D new =
TestD();<BR>&nbsp;=20
    &nbsp;&nbsp;&nbsp;&nbsp;=20
    =
test.SerializeUsingSoapFormatter("sharedEvent_SOAP.xml");<BR>&nbsp;&nbsp;=
=20
    }<BR>&nbsp;<BR></FONT><FONT face=3DArial size=3D2>&nbsp;&nbsp; =
public void=20
    SerializeUsingSoapFormatter(string filename)=20
    {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
<STRONG>XmlTextWriter=20
    writer =3D new XmlTextWriter(filename,=20
    null);<BR></STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    MyRootClass myRootClass =3D new MyRootClass();</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT face=3DArial=20
    size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
BusinessEvent evt =3D=20
    new BusinessEvent("1", "A Test=20
    Event");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    myRootClass.TheSharedEvent =3D evt;</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT face=3DArial=20
    size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
EventCondition ec1 =3D=20
    new EventCondition("2", "Condition=20
    1");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
ec1.TheEvent =3D=20
    evt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    myRootClass.Conditions.Add(ec1);</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT face=3DArial=20
    size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
EventCondition ec2 =3D=20
    new EventCondition("3", "Condition=20
    2");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
ec2.TheEvent =3D=20
    evt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    myRootClass.Conditions.Add(ec2);</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT face=3DArial=20
    size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
XmlTypeMapping=20
    xmlTypeMapping =3D (new=20
    =
SoapReflectionImporter()).ImportTypeMapping(myRootClass.GetType());<BR>&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    XmlSerializer ser =3D new=20
    =
XmlSerializer(xmlTypeMapping);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;=20
    ser.Serialize(<STRONG>writer</STRONG>, myRootClass);<BR>&nbsp;&nbsp; =

    }<BR>}</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT face=3DArial size=3D2>// This is the root class that will =
be=20
    serialized.<BR>public class MyRootClass {<BR>&nbsp;&nbsp;=20
    [XmlElement("BusinessEvent")]<BR>&nbsp;&nbsp; public BusinessEvent=20
    TheSharedEvent;</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; =
[XmlArrayItem(IsNullable=3Dtrue,=20
    Type =3D typeof(EventCondition))]<BR>&nbsp;&nbsp; =
[XmlArray]<BR>&nbsp;&nbsp;=20
    public IList Conditions =3D new ArrayList();<BR>}</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT face=3DArial size=3D2>// An instance of BusinessEvent =
will be shared=20
    by two EventCondition instances<BR>public class BusinessEvent=20
    {<BR>&nbsp;&nbsp; public string Id;</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; =
[XmlAttribute]<BR>&nbsp;&nbsp;=20
    public string DisplayName;</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; public BusinessEvent() =

    {}<BR>&nbsp;&nbsp; public BusinessEvent(string Id, string =
DisplayName)=20
    {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Id =3D=20
    Id;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.DisplayName =3D=20
    DisplayName;<BR>&nbsp;&nbsp; }<BR>}</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT face=3DArial size=3D2>// Two EventCondition instances =
will refer to=20
    the same (single) BusinessEvent instance<BR>public class =
EventCondition=20
    {<BR>&nbsp;&nbsp; public string Id;</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; =
[XmlAttribute]<BR>&nbsp;&nbsp;=20
    public string DisplayName;</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; public BusinessEvent=20
    TheEvent;</FONT></DIV>
    <DIV>&nbsp;</DIV>
    <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; public =
EventCondition()=20
    {}<BR>&nbsp;&nbsp; public EventCondition(string Id, string =
DisplayName)=20
    {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Id =3D=20
    Id;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.DisplayName =3D=20
    DisplayName;<BR>&nbsp;&nbsp; }<BR>}</FONT></DIV></BLOCKQUOTE>
  <BLOCKQUOTE dir=3Dltr=20
  style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
    <DIV><FONT face=3DArial=20
size=3D2></FONT>&nbsp;</DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_002C_01C34C68.A21B8C50--

0
7/17/2003 6:37:57 PM
This is a multi-part message in MIME format.

------=_NextPart_000_0206_01C34D40.DCD46AA0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Thanks.  You learn something new everyday! :-)
  I am sorry if I wasn't clear enough. The with the Soap 1.1 Section 5 =
encoding, EVERY object in the object graph will be serialized as a top =
level element, which does not result in well-formed XML unless you =
enclose the serialized output in a common element. If you don't write a =
common parent element the underlying XmlTextWriter will complain ( throw =
an exception ) when you are attempting to write a 2nd top level element.

  Everything will work once you add a line like this

           XmlSerializer ser =3D new XmlSerializer(xmlTypeMapping);
           writer.WriteStartElement( "myCommonRoot" );
           ser.Serialize(writer, myRootClass);
           writer.WriteEndElement(); // myCommonRoot

  and then manually skip over that element when you deserialize.

  --=20
  HTH
  Christoph Schittko [MVP]
  Software Architect, .NET Mentor
------=_NextPart_000_0206_01C34D40.DCD46AA0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff background=3D"">
<DIV><FONT face=3DArial size=3D2>Thanks.&nbsp; You learn something new =
everyday!=20
:-)</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV><FONT face=3DArial size=3D2>I am sorry if I wasn't clear enough. =
The with the=20
  Soap 1.1 Section 5 encoding, EVERY object in the object graph will be=20
  serialized as a top level element, which does not result in =
well-formed XML=20
  unless you enclose the serialized output in a common element. If you =
don't=20
  write a common parent element the underlying XmlTextWriter will =
complain (=20
  throw an exception ) when you are attempting to write a 2nd top level=20
  element.</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Everything will work once you add a =
line like=20
  this</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT><FONT=20
  face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  XmlSerializer ser =3D new XmlSerializer(xmlTypeMapping);</FONT></DIV>
  <DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  writer.WriteStartElement( "myCommonRoot"=20
  );<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  ser.Serialize(<STRONG>writer</STRONG>, myRootClass);</FONT><BR><FONT=20
  face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;=20
  writer.WriteEndElement(); // myCommonRoot</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>and then manually skip over that =
element when you=20
  deserialize.</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT><BR>--=20
  <BR>HTH<BR>Christoph Schittko [MVP]<BR>Software Architect, .NET=20
Mentor</DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0206_01C34D40.DCD46AA0--

0
sr_spam (4)
7/18/2003 1:25:47 PM
Reply:

Similar Artilces:

XmlSerializer Collection with Collections
Hello I got this working but it is not how I really want it, basically I have an xml file which has a root of <test> and can be filled with 3 different types of <question> elements with different attributes, all share a base set of 4, one of the question types can have children with <option> elements, this is how the xml looks after serialization.... If you notice there is an extra <SelectionList> around the <option>'s in the final <question>, how can I write my class so I don't have this extra <SelectionList> element....my class follows, you ...

In-line objects
I'm trying to design a questionnaire and I've used the drawing tools to put in a lot of lines and boxes. I'd like these to stay where they are, but I'm having some problems. For example: There is a question with some lines below it for the answer. When I make the lines in-line objects they become invisible and move against the left margin. Then if I try to resize them I can't get them perfectly straight again. Please help! When you re-size, hold the shift key down. Working with graphics and objects http://office.microsoft.com/en-us/assistance/CH062524651033.a...

Using a resource (conference room)
I am trying to set up a resource so we can schedule use of our conference room for meetings. I have the free/busy time working for all the people but for the life of me, can not decipher from Outlook help how to actually get the resource in place. I am not running an Exchange server, is this required ? I hope not. Once set up, I figured it shouldn't have to be managed. Help ? Thanks, Doug ...

Adding forms/objects/items to a user entity
As with quotas our sales people also have a quota for phone time. I'm looking for a way in which I can create a tree item in the left pane that I can mirror the quota option but then for minutes per day and then also split into mornring and afternoon. In theory I can see ways of how it should be possible but stumped on the implementation. Does anyone know how I can add 1. a tree item 2. a similar set of entities like quotas to a user? ALL help sincerely appreciated. -- ICT Manager New Horizons: Amsterdam Eksteen, If all users are "online" in otherwords connected to t...

Use variables for a chart
Hello, I have used Excel in the past, but nothing to this extreme. I have a worksheet with about 15-20 columns. At the top of these columns I created a toggle button for each column. One of the columns consist of trimesters, another is in years others have data. What I would like to do is create a chart on my worksheet which would be populated using the trimesters, years, and the data for that particular column. Is this possible or do I have to create a chart for each column? I was wonder maybe I need to run some code behind the button to popluate another column with the particul...

Using VBA to find a value and select a range
I am trying to write a macro that will let me find a specific vale in a specific column, then select part of the row that the value is in, beginnign with a column 31 cells away from the column that the specific value is in. Someone suggested to me that I use an IF statement, but this is all I know about that: IF [value in column B] is “Grand Total” Then select from column AF to the end of the array in that row and copy it and paste a transpose of the values starting in cell I9 of worksheet X. What is the best way for me to accomplish this goal? Does this macro do what you...

vb.net share data
Since I am new to vb.net 2008, I have the following question to ask: Since a solution (.sln file) can have several projects in it, can one project file work with another project file? In other words, can 'object a' in 'project file 1', work with 'object b' in 'project file 2' by using methods in ''object b' where 'properties values' are exposed to 'public' access? For example, can object 'manage finances' in 'project file 1' obtain the 'checking account' values from object 'customer' in &...

sharing workbook
I want share my workbook but to some user only, than others for read only. How to setting that selected user for sharing. EXCEL 2007 Review tab / Changes group / Share Workbook / place a tick in the box called:- Allow changes by more than one user at the same time. This allows allows workbook merging. Hit OK. If my comments have helped please hit Yes. Thanks. "nordiyu" wrote: > I want share my workbook but to some user only, than others for read only. > How to setting that selected user for sharing. Excel has a Sharing feature that allows mu...

Using dual monitors on powerpoint
Hello, for my art project I need to make a powerpoint slide of different colours to aid my art piece. I was wondering if there was any way to incorporate both of my screens, as I have two connected to my PC, and show the simple colous over both screens. Help would be much appreciated, thank you. If they are static presentations (that is, there is no animation, transitions, etc.) and only 1 slide, you can perhaps try the following: 1. Ensure that both your monitors are connected to your PC and are enabled for display. 2. Open one of your presentations in PowerPoint. 3. Click &...

Defining if a cell has an letter / number with in it using IFstate
In a IF statement how do i determine a letter or a number within a cell using Excel 2007 ie IF(D3 = letter; then 1 ; else 0) Thanks =3Dif(istext(d3),1,0) & =3Dif(isnumber(d3),1,0) On Nov 18, 9:42=A0pm, Washeacrim <Washeac...@discussions.microsoft.com> wrote: > In a IF statement how do i determine a letter or a number within a cell u= sing > Excel 2007 > > ie =A0 =A0 =A0IF(D3 =3D letter; then 1 =A0; else 0) > > Thanks =IF(ISNUMBER(D3), "It's a number", "It's text or Boolean") =IF(ISNUMBER(D3), 1,0) But the IF is not needed w...

Ole-object to image
Hi, I've developed an application in Access2K using jet database, but now I want to move the database to MS SQL Server. I've designed the database and done some adjustments to the relations, and now it's time to copy the data. The copying will be runned automatically for each user, so i have to program it using recordsets. It works fine, except copying embedded images. I have a logo field in the mdb-table and when i copy it to SQL Server it won't show in the form no more. I've learned that Access adds a *lot* of header information when you insert an image in an Ole-object ...

Outlook 2003: Is there a way to change folder names that are generated when installed?
In my previous version of Outlook 2000 I had a folder named Junk E-mail. The new 2003 version installed it's own folder named Junk E-mail1 (the 1 because there was already a folder in the old version with the exact name) that is associated with filtering within OL. I have since deleted my original folder, but cannot change the name of Junk E-mail1 to just Junk E-mail because OL does not allow you to change this in the folder list, nor can you even delete this folder. Wondering if there was a registry setting or some other alternative for doing this. I used SpamBayes for filtering in my las...

Copy and paste a chart using a macro
I am trying to copy and paste a chart from one workbook to another and maintain all formatting (including titles, font sizes, colors etc) using an excel macro. So far I have something like this: ActiveSheet.ChartObjects(1).Activate ActiveChart.ChartArea.Select ActiveChart.ChartArea.Copy Workbooks("Chartbook.xls").Worksheet("Section A").Paste Unfortunately, when I paste the chart the axes font size changes as does the plot area. ::Win98SE, Excel 2000:: ** Posted via: http://www.ozgrid.com Excel Templates, Training, Add-ins & Business Software Galore! Free Excel Forum...

Templates: Can I use a Word Template in Publisher?
I'm new to Publisher. I found a Word template I'd like to use in Publisher. Is this possible? Do I have to modify it in any way? Thanks. You can try. "Whitecarp" <anonymous@discussions.microsoft.com> wrote in message news:2B6771FC-6D39-4F57-A541-AD2CBB50BABA@microsoft.com... > I'm new to Publisher. I found a Word template I'd like to use in Publisher. Is this possible? Do I have to modify it in any way? Thanks. You cannot use a Word Template in Publisher. You will have to modify/re-create it. Publisher 2003 may import some of the template feature...

Shared Calendar #7
My company recently installed Outlook and we are able to share calendars. I would like to view 2 shared calendars whenever I open the program, rather than viewing my own. How can I do this? In news:B5A507E2-2198-45BD-ABC3-81971C95192A@microsoft.com, zari <zari@discussions.microsoft.com> typed: > My company recently installed Outlook and we are able to share > calendars. I would like to view 2 shared calendars whenever I open > the program, rather than viewing my own. > > How can I do this? Hi - when you post in here, always include your version, SP level, and mode ...

you have to use search
if you are using search-earn you will earn money in your all searches. you must join the seach-earn its your connecting adress http://www.search-earn.com/ygecek http://www.search-earn.com/egecek http://www.search-earn.com/fttroo ...

XmlSerializer
I'm having a basic problem with the XmlSerializer & i'm at my wits end trying to sort it out i have a basic clas <Serializable()> Class Tes Public Name as Strin End Clas when this serializes i wan <Test><Name>Value</Name></Test the problem is if i use the XmlSerializer clas Dim t as Tes t.Name="Value Dim sb As New StringBuilde Dim sw As New StringWriter(sb Dim Serializer As New XmlSerializer(Message.GetType Serializer.Serialize(sw, t Serializer = Nothin Console.Write(sb.ToStr...

using e-mail templates
A group users wants apply an e-mail template with default texts. To achieve this I have made a massage with the standard texts and saved it as .oft. To apply the template the user has to choose: Tools - Forms - Choose form . and select in the dialogue window in the long list box `User template... (or something like that, I have a Dutch version)). This is not an user-friendly way. I can place a toolbar button with a hyperlink to the template, but still a choice must be made in the long list box. Is there a more user-friendly way to use a e-mail template? Thank you very much. Anne ...

How to use Camera function in Excel
Does anyone have any references/links where I can find out how to use the Camera function in Excel ie. the camera found under TOOLS \ CUSTOMIZE \ COMMANDS \ TOOLS \ CAMERA? It's just take a screen print of a selected area on Excel, you can almost get the same functionality by holding down Shift and do edit>copy picture. The only difference I know of is that using the camera tool it puts in a border in black while the shift <> edit>copy picture version use a non coloured border (it's still there, just not visible) So the camera tool is a bit easier to use and paste aut...

Transfering Outlook Files to a new computer (Using Outlook 2007)
I recently bought a new computer (PC), and want to move my Outlook Account Information (Mail, Calendar, Contacts and Tasks) over to the new computer without having to re-enter everything by hand. I used to have AOL (sorry), and I knew the AOL folder (pfc folder) to copy and paste which stored everything with ease. I merely kept a copy of that AOL pfc folder on a data stick so if ever I had a computer crash, or bought a new computer, all my AOL address book and contact information could be easily transfered. I do not know how to find or access this information (folders/files) with...

Saving shared Excel files
Question about saving excel documents when saving a shared excel file, how do you get it to save to where when you reopen it it will open at the end of a document, and with this being a shared file after other users save it, need to be able to open to the end of file. Thanks Scott scasawyer wrote: > Question about saving excel documents > when saving a shared excel file, how do you get it to save to where when you > reopen it it will open at the end of a document, and with this being a > shared file after other users save it, need to be able to open to the end of > f...

Can delegates use the other persons contacts to create distribution lists
It alsways defaults to the Delegates Contact list. Any help? >-----Original Message----- >It alsways defaults to the Delegates Contact list. > >Any help? >. > Any ideas at all? ...

Pivot Tables + Color + Dynamic Content generation and display
I have a dynamically generated pivot table (generated from actions in another spreadsheet - number of rows and location keeps changing - cant use conditional formatting). The data I currently have displayed on the pivot table is: Resource Project Allocation Jan Allocation Feb -------- ------- -------------- -------------- Resource1 Project1 0.5 0.5 Resource1 Project1 0.25 0.5 Resource1 Total 0.75 1.0 Resource2 Project1... .. I need to (1) Highlight, in red, items where Resource totals are less than 1.00. e.g. Resource 1 Total. Just...

Shared Resources usage
Hello, I'm using ms project 2003. I'm sharing resources in several project, for that I have resource sheet (file that contains resources only). In that sheet, when I'm in the resource usage view, there are some resources marked in red and some of their allocations is marked in red too eventhough the specific allocation is not overallocated. Does anyone know why these allocations are marked in red eventhough there is no overallocation ? Thanx! -- lironm ------------------------------------------------------------------------ lironm's Profile: http://for...

How to protect a shared sheet but allow groups to expand
Hi, I am running Office XP and I am having a problem with protection and groups. On one of my sheets I have grouped some rows so that the plus/minus sign is on the left. Some of the cells are unprotected so they can be updated when the sheet is protected. The problem is that when the sheet is protected you cannot expand or collapse the groups. I found some code on Google that runs when you open the workbook and allows the groups to function properly and the codes works great. However when I share the workbook the code no longer functions and in fact generates an error upon opening the ...