Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8258099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:25:19+00:00 2026-06-08T02:25:19+00:00

For Binary serialization I use public ClassConstructor(SerializationInfo info, StreamingContext ctxt) { this.cars = (OtherClass)info.GetValue(Object,

  • 0

For Binary serialization I use

public ClassConstructor(SerializationInfo info, StreamingContext ctxt) {

    this.cars = (OtherClass)info.GetValue("Object", typeof(OtherClass));
}
public void GetObjectData(SerializationInfo info, StreamingContext ctxt) {
    info.AddString(this.name);
    info.AddValue("Object", this.object);
}

I want to make the same thing for XML serialization (class implements IXmlSerializable interface, because of private property setters), but I don’t know how to put an object to serializer (XmlWriter object).

public void WriteXml( XmlWriter writer ) {
    writer.WriteAttributeString( "Name", Name );
    writer. ... Write object, but how ???
}
public void ReadXml( XmlReader reader ) {
    this.Name = reader.GetAttribute( "Name" );
    this.object = reader. ... how to read ??
}

probably I can use something like this

XmlSerializer xsSubmit = new XmlSerializer(typeof(MyObject));
var subReq = new MyObject();
StringWriter sww = new StringWriter();
XmlWriter writer = XmlWriter.Create(sww);
xsSubmit.Serialize(writer, subReq);
var xml = sww.ToString(); // Your xml

but maybe there is simpler method that uses only XmlWriter object I get from WriteXml method argument

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:25:21+00:00Added an answer on June 8, 2026 at 2:25 am

    I’ve decided to go the way I wrote my question – to use XmlWriter object, which i have to use anyway, even if I go Ofer Zelig’s way.

    namespace System.Xml.Serialization {
        public static class XmlSerializationExtensions {
            public static readonly XmlSerializerNamespaces EmptyXmlSerializerNamespace = new XmlSerializerNamespaces(
                new XmlQualifiedName[] {
                    new XmlQualifiedName("") } );
    
            public static void WriteElementObject( this XmlWriter writer, string localName, object o ) {
                writer.WriteStartElement( localName );
                XmlSerializer xs = new XmlSerializer( o.GetType() );
                xs.Serialize( writer, o, EmptyXmlSerializerNamespace );
                writer.WriteEndElement();
            }
    
            public static T ReadElementObject< T >( this XmlReader reader ) {
                XmlSerializer xs = new XmlSerializer( typeof( T ) );
                reader.ReadStartElement();
                T retval = (T)xs.Deserialize( reader );
                reader.ReadEndElement();
                return retval;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data object that is deep-cloned using a binary serialization. This data
I have a Binary Search Tree, I use template to add any class object
We use .net binary serialization right now to serialize data to persist. It does
I know that if I use binary serialization with WCF I lose interopability. If
I'm trying to build an object that looks something like this: public class MyObject
I have an object that is deserialized with this: public object DeSerializeObject(string filename) {
I use Boost.Serialization to serialize a std::map. The code looks like this void Dictionary::serialize(std::string
My application does a good deal of binary serialization and compression of large objects.
I was using the xml serializer but when I switched to binary serialization, it
using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; VS says, The type or namespace name 'Formatters' does not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.