473,327 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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 XmlAttributeOverrides, but I have
to do it for every class the OutputObject usses. Is there an
"ApplyToAll" kind of feature?

I also tried the defaultNamespace, but it didn't work.
MySerializer = New XmlSerializer(Type:=ClassName),
defaultNamespace:="mynamespace")

Ok let me describe the whole process. What I'm doing is a webservices
that:

1- Input: takes an object "InputObject"
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 "OutputObject". (the class has namespaces. also
it is NOT the same class as in the "InputObject")
7- Output: return the "OutputObject" 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 XmlAttributeOverrides, 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 XmlAttributeOverrides
atts.Xmlns = False
xover.Add(GetType(OutputClassName), atts)
xover.Add(GetType(ClassName1), atts)
xover.Add(GetType(ClassName2), atts)
xover.Add(GetType(ClassName3), atts)
MySerializer = New XmlSerializer(GetType(OutputClassName), xover)
MyObject = CType(oSerializer.Deserialize(oReader), OutputClassName)

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

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

Let's suppose it is really simple, like the following:
<Output>
<element1>value1</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.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
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.google.c om...
Hello,

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

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

I also tried the defaultNamespace, but it didn't work.
MySerializer = New XmlSerializer(Type:=ClassName),
defaultNamespace:="mynamespace")

Ok let me describe the whole process. What I'm doing is a webservices
that:

1- Input: takes an object "InputObject"
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 "OutputObject". (the class has namespaces. also
it is NOT the same class as in the "InputObject")
7- Output: return the "OutputObject" 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 XmlAttributeOverrides, 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 XmlAttributeOverrides
atts.Xmlns = False
xover.Add(GetType(OutputClassName), atts)
xover.Add(GetType(ClassName1), atts)
xover.Add(GetType(ClassName2), atts)
xover.Add(GetType(ClassName3), atts)
MySerializer = New XmlSerializer(GetType(OutputClassName), xover)
MyObject = CType(oSerializer.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.Serialization.XmlRootAttribute(Namespac e="mymessagenamespace",
IsNullable=false)]

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.google.c om...
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.Serialization.XmlRootAttribute(Namespac e="mymessagenamespace",
IsNullable=false)]

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**************@TK2MSFTNGP11.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.google.c om...
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.Serialization.XmlRootAttribute(Namespac e="mymessagenamespace",
IsNullable=false)]

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
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...
5
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...
3
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...
8
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...
1
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...
0
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...
0
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...
0
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...
9
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. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.