when my class gets serialized, I'd like not to have the following
attributes in root element:
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
ho can I get rid of them? I already tried the following:
[XmlRootAttribute(ElementName="myRoot", Namespace="")]
please help!
--------
Francesco "Matro" Martire
RealPopup, the freeware winpopup replacer
http://www.realpopup.it
MaTreo, freeware frontscreen for your Treo
http://www.realpopup.it/matreo
To get rid of them you have to pass in an empty new XmlSerializerNamespaces
object to the Serialize() call:
serializer.Serialize( writer, yourObject, new XmlSerializerNamespaces() );
HTH,
--
Christoph Schittko
Software Architect
Mshow - a division of InterCall
"matro" <ma...@usa.net> wrote in message
news:mmhvjug3vphsj1p9o...@4ax.com...
>To get rid of them you have to pass in an empty new XmlSerializerNamespaces
>object to the Serialize() call:
>
>serializer.Serialize( writer, yourObject, new XmlSerializerNamespaces() );
it doesn't work for me:
// this is to tell XmlSerializer to use UTF8 encoding
System.IO.MemoryStream mystr=new System.IO.MemoryStream();
XmlSerializer myser=new XmlSerializer(typeof(ftService.ftCommand));
XmlTextWriter writer = new System.Xml.XmlTextWriter(mystr,
System.Text.Encoding.UTF8);
// as Christoph said
myser.Serialize(writer, myCommand, new XmlSerializerNamespaces());
on the other hand, the initial serialized class looks like the
following:
[XmlRootAttribute(ElementName="myCommand")]
public class ftCommand
produced XML looks like the following:
<?xml version="1.0" encoding="utf-8"?><myCommand
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
...
You actually have to add an empty namespace declaration to the
XmlSerializerNamespaces object:
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add( "", "" );
myser.Serialize(writer, myCommand, ns );
will do the trick.
HTH,
--
Christoph Schittko
Software Architect
Mshow - a division of InterCall
"matro" <ma...@usa.net> wrote in message
news:aj60kuge5bdttqln5...@4ax.com...
>Yeah, I should not post before I had time for my morning coffee ...
:-)
warning: I still got to take it this morning...
>You actually have to add an empty namespace declaration to the
>XmlSerializerNamespaces object:
thank you Cristoph, as it works.
now, I got another place where I take advantage of serializing,
through the XmlMessageFormatter class, which is intended to use with
MSMQ serialization support. I'd like to have the same (ie. get rid of
those xmlns attributes) with it. the class internally uses
XmlSerializer, but I don't know how to 'reach' it to tell about blank
namespaces.
The XmlMessageFormatter does not expose access to the serializers it uses,
or you could override the Write method and call the Serialize() method
accordingly.
Looks like you only choice is to build your own message formatter that
implements IMessageFormatter. It's not hard, merely a hashtable of
XmlSerializer objects.
HTH,
--
Christoph Schittko
Software Architect
Mshow - a division of InterCall
"matro" <ma...@usa.net> wrote in message
news:8902kukd2a06hfh12...@4ax.com...
>OK ... I drank my coffee this morning ;)
:-)
>Looks like you only choice is to build your own message formatter that
>implements IMessageFormatter. It's not hard, merely a hashtable of
>XmlSerializer objects.
this could be interesting to do, I'll think about it. thank you for
support you're giving to all ng readers!