Home All Groups Group Topic Archive Search About

Re: How to tell the XmlSerializer to ignore all namespaces

Author
16 Nov 2004 9:51 PM
Dino Chiesa [Microsoft]
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(Namespace="", 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



Show quote
"Alexis" <is4fu***@yahoo.com> wrote in message
news:b2502f41.0411140909.5464f2a2@posting.google.com...
> 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

Author
17 Nov 2004 4:14 PM
Alexis
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(Namespace="mymessagenamespace",
IsNullable=false)]

but the xml document still wil not have the namespaces

/Alexis
Author
18 Nov 2004 3:02 PM
Dino Chiesa [Microsoft]
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

Show quote
"Alexis" <is4fu***@yahoo.com> wrote in message
news:b2502f41.0411170814.699b6d82@posting.google.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.Serialization.XmlRootAttribute(Namespace="mymessagenamespace",
> IsNullable=false)]
>
> but the xml document still wil not have the namespaces
>
> /Alexis
Author
23 Nov 2004 2:39 PM
Alexis
Dino that is what I did in the first place and there is the problem.
Look at the first posting.

Show quote
"Dino Chiesa [Microsoft]" <din***@online.microsoft.com> wrote in message news:<#M0urAYzEHA.1452@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" <is4fu***@yahoo.com> wrote in message
> news:b2502f41.0411170814.699b6d82@posting.google.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.Serialization.XmlRootAttribute(Namespace="mymessagenamespace",
> > IsNullable=false)]
> >
> > but the xml document still wil not have the namespaces
> >
> > /Alexis

AddThis Social Bookmark Button