473,608 Members | 2,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Ser ialization.XmlR ootAttribute([Namespace]:="mynamespace" ,
IsNullable:=Fal se)> _
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
XmlAttributeOve rrides 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 XmlAttributeOve rrides

atts.Xmlns = False

xover.Add(GetTy pe(ClassName), atts)

MyObject = CType(oSerializ er.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
Nov 12 '05 #1
5 10047

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.publi c.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.Ser ialization.XmlR ootAttribute([Namespace]:="mynamespace" ,
IsNullable:=Fal se)> _
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
XmlAttributeOve rrides 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 XmlAttributeOve rrides

atts.Xmlns = False

xover.Add(GetTy pe(ClassName), atts)

MyObject = CType(oSerializ er.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


Nov 12 '05 #2
Q: 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?
A: These classes are used by a webservice. When the client add the web
reference the proxy classes gererated brings all the classes together.
So I do need the namespaces but only because of this issue.

Q: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?
A: No I don't need to serialize and deserialize the same object. I
will only deserialize from an xml document that don't have namespaces
and I don't have control over it. but also the class for the object
the deserialize will created has namespaces. (need because first
issue)

I also tried the defaultNamespac e, but it didn't work.
MySerializer = New XmlSerializer(T ype:=ClassName) ,
defaultNamespac e:="mynamespace ")

Ok let me add something else. What I'm doing is a webservices that:

1- Input: takes an object "InputObjec t"
2- serialize it
3- transform the resulted xml document
4- send the transformed xml doc to a server.
5- receive an xml doc from the server. (no namespaces on it and no
control over it)
6- deserialize it to "OutputObje ct". (the class has namespaces. also
it is NOT the same class as in the "InputObjec t")
7- Output: return the "OutputObje ct" to the client. Again the Input
and Output objects use different set of classes.)

So at point 6 I need to deserialize an xml doc with no namespaces to
an object which class has namespaces on it. I hope I explained myself
better this time.

Ok I can resolve this issue by using XmlAttributeOve rrides, but I have
to do it for every class the OutputObject usses. Is there an
"ApplyToAll " kind of feature?

Dim atts As New XmlAttributes
Dim xover As New XmlAttributeOve rrides
atts.Xmlns = False
xover.Add(GetTy pe(OutputClassN ame), atts)
xover.Add(GetTy pe(ClassName1), atts)
xover.Add(GetTy pe(ClassName2), atts)
xover.Add(GetTy pe(ClassName3), atts)
MySerializer = New XmlSerializer(G etType(OutputCl assName), xover)
MyObject = CType(oSerializ er.Deserialize( oReader), OutputClassName )

Please Help I have being working on this for two days.

Thanks,
Alexis
Nov 12 '05 #3
Hello Christoph Schittko,
You did not answered my question. I guess you are too busy or you just
don't know the answer.
Thanks anyway for trying.
Nov 12 '05 #4

Yes, I do have a paying day job that I have to tend to ... answering
questions in newsgroups is something I do on my personal time. I try my
best to answer timely and follow up, but sometimes other issues (the
ones that help me pay my bills take precedence).

Now with all that ... would you still like me to help or have you
figured it out on your own?

Christoph
-----Original Message-----
From: Alexis [mailto:is****** @yahoo.com]
Posted At: Monday, November 15, 2004 10:35 AM
Posted To: microsoft.publi c.dotnet.xml
Conversation: XmlSerializer Namespace problem
Subject: Re: XmlSerializer Namespace problem

Hello Christoph Schittko,
You did not answered my question. I guess you are too busy or you just
don't know the answer.
Thanks anyway for trying.


Nov 12 '05 #5
No, I have not found a way to resolve it.
I'm sorry for the way I wrote my previous posting. This issue has
frustrated me so much. I'm thinking there may be no way of fixing it.
This XmlSerializatio n is not completed yet (I beleive). It will not be
the first time microsoft releases something not fully worked out. Any
way I still need to find some work around for it. Well as I said I
already have one but I'm not happy about it. Has that happended to
you? You have finished coding but still beleive there got to be a
better way.
Any way, yes if you still want to take another look to this issue you
are more than welcome. I'll really appreciate it.
Thanks in advance.
/Alexis
Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1292
by: ajay.sonawane | last post by:
Hello there You need to create namespace in order to add your own element, But how can I create namespace file? Does it need to post that namespace to some authorized person of RSS? For Example. I wish to add my own element in RSS feed, so I will go for namespace, But How to create namespace file? What is the structure of namespace files that I need to follow? What is meant by defining those elements in namespace? What I need to do to...
0
275
by: Alexis | last post by:
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(:="mynamespace", IsNullable:=False)> _ Public Class ClassName
3
2342
by: Sandy | last post by:
Hi, I have two files as folllows file1.cpp #include<iostream> using namespace std; namespace { void show(); void fun() { cout<<"fun called\n"; } }
6
1649
by: SpOiLeR | last post by:
Why doesn't following code compile? Problem line is commented in code. ---------------------- Cut here------------------------------- #include <iostream> #include <list> #include <string> using namespace std;
2
4556
by: tomek.romanowski | last post by:
Hi ! I have problem with validating of the document with multiple namespaces. The odd thing is, that my data work O'K when I test it under XMLSpy but it doesn't work with my C# code. My first 'main' schema is as follows: incr2.xsd ---------- <xs:schema targetNamespace="http://vit.volvo.com/dept9272/2004/ESB"
10
6646
by: anders | last post by:
I have 2 external assemblies A1 and A2 that both define class X in the global namespace. I need to use both assemblies in my VB project but the names X are ambiguous. How can I get around this problem? Is there a way to refer to the assembly, f.ex. A1.X and A2.X (this syntax does not compile). Or can I change the name X in the Imports directive? Again the problem is how do I refer to the 2 different X'es in assemblies A1 and A2:
0
2363
by: ryan | last post by:
I've been tasked with consuming a Perl web service that was written by a person in a different department of my company. The problem is it's the guy's first attempt at web services and he doesn't know how to create the WDSL. I created web service with Visual Studio that mimics his service and after some tweaking of the soapAction in the WSDL I'm able to call his service successfully. When I use SOAPScope to look the messages being sent and...
0
894
by: SMart | last post by:
I am having a problem with a C# dll in my Visual Studio 2005 ASP.NET web site project: when I add a reference to a certain the dll, it tells me that the type or namespace “Log” does not exist in the namespace SGS.DataServices. The namespace that I am looking for is SGS.DataServices.Log. When I type SGS.DataServices the namespace that is available is “System”. When that dll was initially written, the namespace was in fact...
5
1440
by: michael.d.pedersen | last post by:
Hello group, I am new to Visual C++ 8 and have a seemingly trivial problem using namespaces. The scenario: I have two classes, TestClass1 and TestClass2, in the namespace Test. I would like to create a reference to TestClass2 in TestClass1; but the compiler doesn't seem to recognize the namespace Test and any classes in it. Here are my class definitions and declarations:
0
8067
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8483
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5479
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3967
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2477
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1336
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.