<< Absolutely. You can pass an unconfigurad XmlSerializerNamespaces
instance to the Serialize call to control this. >>

I must be doing something wrong but I can't get rid of the xmlns: ... by
doing what is suggested. 

Here is my code to serialize to a string:

XmlSerializer serializer = new XmlSerializer(typeof(TestClass));
TestClass testClass  = new TestClass();
StringWriter writer = new StringWriter();
serializer.Serialize(writer, testClass ,new XmlSerializerNamespaces());


Here is my class

        public class TestClass
        {
                public TestClass()
                {
                }

                [XmlAttributeAttribute]
                public string ClassID = "123";

                public string Name = "Bob";
                public int Language = 1;
        }

Here is my output:
        
<?xml version="1.0" encoding="utf-16"?>
<TestClass xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; ClassID="123">
  <Name>Bob</Name>
  <Language>1</Language>
</TestClass>



What I really want is
<?xml version="1.0" encoding="utf-16"?>
<TestClass      ClassID="123"">
  <Name>Bob</Name>
  <Language>1</Language>
</TestClass>"   string


Thanks for any help.

Brian










-----Original Message-----
From: Marsh, Drew [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, May 01, 2002 5:27 PM
To: [EMAIL PROTECTED]
Subject: Re: [DOTNET] XMLSerialisation options...

Dean Cleaver [mailto:[EMAIL PROTECTED]] wrote:

> 1. The classes you want serialised have to be public - but
> this isn't really what I wanted for this project - I wanted
> to hide the implementation from the "end user" of this
> component - is there any way to avoid this?

Sorry... that's just the way it was designed. The XmlSerializer is not a
true IFormatter and does not use reflection which enables it to be used
in
less secure scenarios, but this means it can only act on public types
and
members.

> 2. The serialiser produced this:
>
> <transaction xmlns:xsd="http://www.w3.org/2001/XMLSchema";
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> type="B2B_REQUEST_STATUS">
>
> Where all I wanted was:
>
> <transaction type="B2B_REQUEST_STATUS">
>
> Is there a way to suppress the above attributes? I've looked
> in the docs, but can't find anything...

Absolutely. You can pass an unconfigurad XmlSerializerNamespaces
instance to
the Serialize call to control this.

HTH,
Drew

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to