XmlSerializer doesn't write the namespace
-
Hi there, I'm currently trying to serialize a wsdl.exe generated object
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.1432")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://myNamespace/")]
public partial class marketDataEventV1 { //...using the following lines of code:
marketDataEventV1 mdEvent = CreateMarketDataEventV1();
XmlSerializer ser = new XmlSerializer(typeof(marketDataEventV1));StringBuilder sb = new StringBuilder();
ser.Serialize(new StringWriter(sb), mdEvent);Now, having a look to
sb.ToString()
shows, that the result (string) does not contain the namespace declaration. I wonder now, how to get the serializer taking account for the namespace?! Thanks in advance! -
Hi there, I'm currently trying to serialize a wsdl.exe generated object
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.1432")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://myNamespace/")]
public partial class marketDataEventV1 { //...using the following lines of code:
marketDataEventV1 mdEvent = CreateMarketDataEventV1();
XmlSerializer ser = new XmlSerializer(typeof(marketDataEventV1));StringBuilder sb = new StringBuilder();
ser.Serialize(new StringWriter(sb), mdEvent);Now, having a look to
sb.ToString()
shows, that the result (string) does not contain the namespace declaration. I wonder now, how to get the serializer taking account for the namespace?! Thanks in advance!Take a look at this[^] Use the XmlSerializerNamespaces to add your namespace and pass it to the ser.Serialize overload method.
Tarakeshwar Reddy There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi
-
Take a look at this[^] Use the XmlSerializerNamespaces to add your namespace and pass it to the ser.Serialize overload method.
Tarakeshwar Reddy There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi
Thanks, I've already noticed
XmlSerializerNamespaces
, but this way, I need to code which namespace belongs to which object. But that's exactly what the[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://myNamespace/")]
-attribute says. So how to tell the serializer to have a look for these attributes? I expected that as a default.. -
Thanks, I've already noticed
XmlSerializerNamespaces
, but this way, I need to code which namespace belongs to which object. But that's exactly what the[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://myNamespace/")]
-attribute says. So how to tell the serializer to have a look for these attributes? I expected that as a default..May be XmlRootAttribute[^] is what you need to use.
Tarakeshwar Reddy There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi
-
May be XmlRootAttribute[^] is what you need to use.
Tarakeshwar Reddy There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi
That works, thank you. However, I did not expect to need to change the generated code.