Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Serializing an object to XML and load into an XMLDocument

11 views
Skip to first unread message

@nospamforactiprosoftware.com Bill Henning

unread,
Feb 20, 2003, 6:56:07 AM2/20/03
to
Hello.... is it possible to serialize an object to XML by using the
XmlSerializer and place the results into an XMLDocument?

I was trying to do something where I create a MemoryStream and write to that
with the serializer and then load the results into an XMLDocument using the
Load method but it throws an exception since the XML that was produced
contains the header <? XML ?> tag in it.

A requirement is that I have to do this in memory (i.e. no saving to files).

Thanks,

--

Bill Henning
Actipro Software LLC

Check out our Wizard, DockableWindow, TabStripPanel controls for .NET at:
http://www.actiprosoftware.com/products/dotnet/


Kirk Allen Evans

unread,
Feb 20, 2003, 11:41:51 AM2/20/03
to
System.IO.MemoryStream mem = new System.IO.MemoryStream();
yourSerializer.Serialize(mem, yourObject);
mem.Position = 0;
XmlDocument doc = new XmlDocument();
doc.Load(mem);


--
Kirk Allen Evans
Author, "XML And ASP.NET", New Riders Publishing
www.xmlandasp.net
http://dotnetweblogs.com/kaevans

"Bill Henning" <please @ nospamforactiprosoftware.com> wrote in message
news:#JxgNcN2...@TK2MSFTNGP09.phx.gbl...

Chris Lovett

unread,
Feb 21, 2003, 2:15:59 AM2/21/03
to
Or better still, use the XmlNodeWriter I published on
http://www.gotdotnet.com and do the following:

XmlDocument doc = new XmlDocument();

yourSerializer.Serialize(new XmlNodeWriter(doc), yourObject)

and avoid the textifying and re-parsing of the XML strings.

Kirk Allen Evans

unread,
Feb 21, 2003, 10:30:59 AM2/21/03
to
Very cool.


--
Kirk Allen Evans
Author, "XML And ASP.NET", New Riders Publishing
www.xmlandasp.net
http://dotnetweblogs.com/kaevans


"Chris Lovett" <nospam@!please.net> wrote in message
news:v5bkhfa...@corp.supernews.com...

0 new messages