[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

How to get rid of xlmns:xsd and xlmns:xsi in xml file generated by XmlSerializer

Ever Olano

7/13/2002 1:41:00 AM

How do I get rid of the xlmns:xsd and xlmns:xsi attributes in the XML file
generated by XmlSerializer.Serialize()? I thought that passing an empty
XmlSerializerNamespaces object would do it but it didn't. :(

Thanks!


4 Answers

mickey williams

7/13/2002 2:46:00 AM

0

This is what I use:

XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add(string.Empty, string.Empty);
XmlSerializer serializer = new XmlSerializer(typeof(Order));
StringWriter stringWriter = new StringWriter();
XmlNoPrefixTextWriter writer = new XmlNoPrefixTextWriter(stringWriter);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.Namespaces = false;
serializer.Serialize(writer, order, namespaces);

XmlNoPrefixTextWriter is just a subclass of XmlTextWriter that doesn't emit
a document prefix.

--
Mickey Williams
Author, "Microsoft Visual C# .NET", Microsoft Press


"Ever Olano" <no@spam.com> wrote in message
news:el2s72fKCHA.2736@tkmsftngp13...
> How do I get rid of the xlmns:xsd and xlmns:xsi attributes in the XML file
> generated by XmlSerializer.Serialize()? I thought that passing an empty
> XmlSerializerNamespaces object would do it but it didn't. :(
>
> Thanks!
>
>


Ever Olano

7/15/2002 9:29:00 PM

0

Hi, Mickey. It looks like you wrote XmlNoPrefixTextWriter yourself as I
could not find it in the documentation. What did you have to do
specifically to disable the prefix?

Thanks,
Ever

"Mickey Williams" <mw@codevtech.com> wrote in message
news:uRtBZagKCHA.2324@tkmsftngp13...
> This is what I use:
>
> XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
> namespaces.Add(string.Empty, string.Empty);
> XmlSerializer serializer = new XmlSerializer(typeof(Order));
> StringWriter stringWriter = new StringWriter();
> XmlNoPrefixTextWriter writer = new XmlNoPrefixTextWriter(stringWriter);
> writer.Formatting = Formatting.Indented;
> writer.Indentation = 4;
> writer.Namespaces = false;
> serializer.Serialize(writer, order, namespaces);
>
> XmlNoPrefixTextWriter is just a subclass of XmlTextWriter that doesn't
emit
> a document prefix.
>
> --
> Mickey Williams
> Author, "Microsoft Visual C# .NET", Microsoft Press
>
>
> "Ever Olano" <no@spam.com> wrote in message
> news:el2s72fKCHA.2736@tkmsftngp13...
> > How do I get rid of the xlmns:xsd and xlmns:xsi attributes in the XML
file
> > generated by XmlSerializer.Serialize()? I thought that passing an empty
> > XmlSerializerNamespaces object would do it but it didn't. :(
> >
> > Thanks!
> >
> >
>
>


mickey williams

7/15/2002 10:16:00 PM

0


"Ever Olano" <ever@nospam.com> wrote in message
news:uBQ7#WDLCHA.2380@tkmsftngp04...

> It looks like you wrote XmlNoPrefixTextWriter yourself as I
> could not find it in the documentation. What did you have to do
> specifically to disable the prefix?
>

Just implement WriteStartPrefix as a no-op method. Here's what I use, but I
don't think I wrote it myself, so I don't take any credit - I seem to think
I got it from somebody else on Usenet or on the DM mailing list.

public class XmlNoPrefixTextWriter : XmlTextWriter
{
public XmlNoPrefixTextWriter(System.IO.TextWriter w) : base(w) {}
public override void WriteStartDocument() {}
}

--
Mickey Williams
Author, "Microsoft Visual C# .NET", Microsoft Press


Ever Olano

7/16/2002 1:43:00 AM

0

Thanks, I'll try that!

"Mickey Williams" <mw@codevtech.com> wrote in message
news:OC$5SxDLCHA.1608@tkmsftngp09...
>
> "Ever Olano" <ever@nospam.com> wrote in message
> news:uBQ7#WDLCHA.2380@tkmsftngp04...
>
> > It looks like you wrote XmlNoPrefixTextWriter yourself as I
> > could not find it in the documentation. What did you have to do
> > specifically to disable the prefix?
> >
>
> Just implement WriteStartPrefix as a no-op method. Here's what I use, but
I
> don't think I wrote it myself, so I don't take any credit - I seem to
think
> I got it from somebody else on Usenet or on the DM mailing list.
>
> public class XmlNoPrefixTextWriter : XmlTextWriter
> {
> public XmlNoPrefixTextWriter(System.IO.TextWriter w) : base(w) {}
> public override void WriteStartDocument() {}
> }
>
> --
> Mickey Williams
> Author, "Microsoft Visual C# .NET", Microsoft Press
>
>