I'm not sure I understand your situation correctly. It sounds like you
don't need XML namespaces because the (possibly implied) schema your
using does not define a formal namespace.
If you don't need XML namespaces at all, would separate .NET namespaces
for the different classes do the trick? Then don't add XML namespaces at
all?
Otherwise, if you actually need to create XML documents that include the
XML namespace declaration, but deserialize XML documents without the
namespace declaration then you could add a default namespace declaration
to the document to deserialize, for example using an XSLT
transformation. However, this approach will carry a pretty significant
overhead if you're deserializing large documents.
Also, is the type of the deserialized objects relevant, i.e. do you ever
need to serialize an object from a previously deserialized instance or
could you get away with two distinct sets of classes; one that carries
the Xml serialization attributes defining the XML namespaces and one
that doesn't?
HTH,
Christoph Schittko
MS MVP XML
http://weblogs.asp.net/cschittko -----Original Message-----
From: Alexis [mailto:is******@yahoo.com]
Posted At: Wednesday, November 10, 2004 4:30 PM
Posted To: microsoft.public.dotnet.xml
Conversation: XmlSerializer Namespace problem
Subject: XmlSerializer Namespace problem
Hello,
I have a set of classes I created from schema files using the xsd.exe
tool. I'm using namespaces in the clases ( I had to because I have
some classes with the same name but not the same class )
Here is how a given class wil looks like.
<System.Xml.Serialization.XmlRootAttribute([Namespace]:="mynamespace",
IsNullable:=False)> _
Public Class ClassName
End Class
So far so good.
My problem is that I want to deserialize the xml document back, but
the xml document don't have the namespaces. I use the
XmlAttributeOverrides collection to solve the problem by ignoring the
namespaces, but so far I have to add an XmlAttribute for each type
(Class) I want to override.
something like this:
Dim atts As New XmlAttributes
Dim xover As New XmlAttributeOverrides
atts.Xmlns = False
xover.Add(GetType(ClassName), atts)
MyObject = CType(oSerializer.Deserialize(oReader), ClassName)
Is there a way I can tell the serializer to ignore the namespaces for
all types without having to write each type?
Thanks,
Alexis