Connecting Tech Pros Worldwide Forums | Help | Site Map

serialisation : remove defaut attribute

msnews.microsoft.com
Guest
 
Posts: n/a
#1: Nov 11 '05
Hi

Here is another EASY question

When you serialise an object in .NET, serialisation adds defaut attributes
that I dont care

EXEMPLE :
<root_test xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
.......
....
</root_test>

my class is :
Public Class root_test
....
end class

I dont want these parameters...
I just want this : <root_test>....</root_test>

how can i do?????
thanks for this answer

Bye bye

lobrys









Oleg Tkachenko
Guest
 
Posts: n/a
#2: Nov 11 '05

re: serialisation : remove defaut attribute


msnews.microsoft.com wrote:
[color=blue]
> Here is another EASY question
>
> When you serialise an object in .NET, serialisation adds defaut attributes
> that I dont care
>
> EXEMPLE :
> <root_test xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> ......
> ...
> </root_test>
>
> my class is :
> Public Class root_test
> ...
> end class
>
> I dont want these parameters...
> I just want this : <root_test>....</root_test>
>
> how can i do?????[/color]

Test test = new Test();
XmlSerializer serializer = new XmlSerializer(typeof(Test));
//Here is the trick
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
serializer.Serialize(Console.Out, test, ns);

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

lobrys
Guest
 
Posts: n/a
#3: Nov 11 '05

re: serialisation : remove defaut attribute


thanks a lot
It's working perfectly

lobrys



"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> a écrit dans le message
de news: udoKmxLYDHA.2464@TK2MSFTNGP09.phx.gbl...[color=blue]
> msnews.microsoft.com wrote:
>[color=green]
> > Here is another EASY question
> >
> > When you serialise an object in .NET, serialisation adds defaut[/color][/color]
attributes[color=blue][color=green]
> > that I dont care
> >
> > EXEMPLE :
> > <root_test xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> > ......
> > ...
> > </root_test>
> >
> > my class is :
> > Public Class root_test
> > ...
> > end class
> >
> > I dont want these parameters...
> > I just want this : <root_test>....</root_test>
> >
> > how can i do?????[/color]
>
> Test test = new Test();
> XmlSerializer serializer = new XmlSerializer(typeof(Test));
> //Here is the trick
> XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
> ns.Add("", "");
> serializer.Serialize(Console.Out, test, ns);
>
> --
> Oleg Tkachenko
> http://www.tkachenko.com/blog
> Multiconn Technologies, Israel
>[/color]


Closed Thread