Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: XML Serialization - Remove XML-instance namespace?

2 views
Skip to first unread message

Martin Honnen

unread,
Mar 17, 2008, 8:45:10 AM3/17/08
to
Spam Catcher wrote:

> When I'm serializing my objects to XML, .NET seems to put the following
> namespace into certain elements:
>
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
> Does anyone know what its for?

XML serialization is based on W3C XSD schemas. These namespaces are the
instance namespace and the schema namespace, depending on the
serialization attributes there might be attributes like xsi:type in the
serialized markup for which the namespace declarations are necessary.

> Is there a way to prevent .NET from adding
> this information?

Why do you want top prevent them? Namespace declarations do no harm
usually. I think the only way to prevent them is to set up an XmlWriter
that suppresses these attributes and pass that writer to the Serialize
method.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Spam Catcher

unread,
Mar 17, 2008, 11:09:17 AM3/17/08
to
Martin Honnen <maho...@yahoo.de> wrote in news:#eQXBzCiIHA.1188
@TK2MSFTNGP04.phx.gbl:

>> Is there a way to prevent .NET from adding
>> this information?
>
> Why do you want top prevent them? Namespace declarations do no harm
> usually. I think the only way to prevent them is to set up an XmlWriter
> that suppresses these attributes and pass that writer to the Serialize
> method.

Because the customer's XML specification does not have these declarations
:-)

I found an example online on how to remove the declaration (by passing in a
blank XML namespace), but I can't seem to create a custom XML serializer to
save me from passing in the custom namespaces each time I need a serializer
.

--
spamho...@rogers.com (Do not e-mail)

0 new messages