473,657 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to tell the XmlSerializer to ignore all namespaces

Hello,

Is there a way of telling the XmlSerializer to ignore all namespaces
when deserializing.

I'm using XmlAttributeOve rrides, but I have
to do it for every class the OutputObject usses. Is there an
"ApplyToAll " kind of feature?

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

Ok let me describe the whole process. 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.

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 4 days.

Thanks,
Alexis
Nov 12 '05 #1
4 15722
can I see an example of the OutputObject?

Let's suppose it is really simple, like the following:
<Output>
<element1>value 1</element1>
<element2 name="something "/>
<element3>
<subelt>foo</subelt>
</element3>
</Output>

If I run this through xsd.exe, I can infer an XSD from it. Then if I run
xsd.exe /c on that XSD, I can generate a class that the XmlSerializer will
produce on de-serialization of the example XML document. The generated
Output class is annotated with
[System.Xml.Seri alization.XmlRo otAttribute(Nam espace="", IsNullable=fals e)]
How are you defining OutputObject and how is the mapping between the output
xml document and the OutputObject class defined?

-Dino

--
Dino Chiesa
Microsoft Developer Division
d i n o c h @ OmitThis . m i c r o s o f t . c o m

"Alexis" <is******@yahoo .com> wrote in message
news:b2******** *************** ***@posting.goo gle.com...
Hello,

Is there a way of telling the XmlSerializer to ignore all namespaces
when deserializing.

I'm using XmlAttributeOve rrides, but I have
to do it for every class the OutputObject usses. Is there an
"ApplyToAll " kind of feature?

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

Ok let me describe the whole process. 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.

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 4 days.

Thanks,
Alexis

Nov 12 '05 #2
You are so far correct in the way you described it.
Now I had to modified the classes to add namepaces to it.

now the Output class is annotated with
[System.Xml.Seri alization.XmlRo otAttribute(Nam espace="mymessa genamespace",
IsNullable=fals e)]

but the xml document still wil not have the namespaces

/Alexis
Nov 12 '05 #3
I don't understand why you are adding namespaces to the class if the actual
document will not have namespaces.

Maybe you can look into the attribute overrides that are possible in XML
Serialization - perhaps that will do what you want.
-D

"Alexis" <is******@yahoo .com> wrote in message
news:b2******** *************** ***@posting.goo gle.com...
You are so far correct in the way you described it.
Now I had to modified the classes to add namepaces to it.

now the Output class is annotated with
[System.Xml.Seri alization.XmlRo otAttribute(Nam espace="mymessa genamespace",
IsNullable=fals e)]

but the xml document still wil not have the namespaces

/Alexis

Nov 12 '05 #4
Dino that is what I did in the first place and there is the problem.
Look at the first posting.

"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote in message news:<#M******* *******@TK2MSFT NGP11.phx.gbl>. ..
I don't understand why you are adding namespaces to the class if the actual
document will not have namespaces.

Maybe you can look into the attribute overrides that are possible in XML
Serialization - perhaps that will do what you want.
-D

"Alexis" <is******@yahoo .com> wrote in message
news:b2******** *************** ***@posting.goo gle.com...
You are so far correct in the way you described it.
Now I had to modified the classes to add namepaces to it.

now the Output class is annotated with
[System.Xml.Seri alization.XmlRo otAttribute(Nam espace="mymessa genamespace",
IsNullable=fals e)]

but the xml document still wil not have the namespaces

/Alexis

Nov 12 '05 #5

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

Similar topics

4
1980
by: Maersa | last post by:
Hi All, When using XmlSerializer is there anyway of keeping "xsi", "xsd" namespaces and PI appearing in the xml file ? <?xml version="1.0"?> <myClass xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="Test" Visible="false" />
5
10067
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
4508
by: Loui Mercieca | last post by:
Hi, I have created a class, named FormField , which basically contains two fields, name and value. I have set the tag before the class and the field is set as an XmlAttribute whil the name as XmlText. In my main class, i have created an arraylist which contains a collection of this class FormField. Basically its: public void Add( string sName, string sValue )
8
5446
by: cd~ | last post by:
I can provide a test app, the news server won't allow me to post the files because they are too large (93KB and 1.2KB) I downloaded the ESRI ArcXml schema and generated the classes from the schema using xsd.exe, which took a while because xsd doesn't handle recursive elements very well (StackOverFlow exception during generation). Now that I have the classes I am trying to serialize them to an xml document to send to ArcIMS to generate...
1
5279
by: ben | last post by:
Is there anyway to force the XMLSerializer to use fully qualified namespaces for when serializing? I was in the midsts of implementing EnterpriseServices configurations using a file store and XMLSerialization when I got clubbed over the head by the serializer because I have two different classes: CompanyA.Risk.Server.Settings and CompanyA.Risk.Client.Settings CompanyA.Risk.Server.Settings contains an array of
0
2034
by: PSingh | last post by:
Hi, I know this is a frequently asked question but have tried several combinations and cant seem to figure this out. I am serializing my object as follows: XmlSerializer serializer = new XmlSerializer(data.GetType()); StringWriter writer = new StringWriter(); XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add("", "");
0
2622
by: =?Utf-8?B?QW1hemVkc2FpbnQ=?= | last post by:
The simple constructors of XMLSerializer class caches the typed serializer once it is generated. (Probably as you know, other XMLSerializer constructors will result in a memory leak because they will generate the assembly each time instead of using the cached one) a) When an XMLSerializer is used from ASP.NET, where exactly the generated typed serializer is getting cached? What is the probability/crieteria for the object in the cache...
0
2797
by: theonlydavewilliams | last post by:
Hi there I'm hoping there's an easy answer to a (hopefully) not too long-winded issue... I'm building a C# web client using a proxy wsdl.exe'd from a wsdl file and six schemas, each in a different namespace. Some schemas extend complex types in others. When i get a soap:Fault from my test server it could contain a serialized exception object (called fault) from one of two of these schemas (and different namespaces, call them xmlns:b0="ns1" and...
9
3287
by: =?Utf-8?B?ai5hLiBoYXJyaW1hbg==?= | last post by:
Hi, I have a schema that has an optional element, fieldTag4000Field. If the element is omitted from the XML request, when it is deserialized, it will be null when I check it - which is fine. What happens when the element is supplied as <fieldTag4000Field/(empty), it does not equate to null. I want to be able handle this at the deserialization level rahter than in my edits later.
0
8324
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8740
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...
0
8617
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
7352
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5642
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
4173
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...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
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
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.