?
=?ISO-8859-1?Q?=22Andr=E9s_G=2E_Aragoneses_=5B_kno
Hello.
I am creating a class that is derived from one that comes from an
auto-generated code from a webservice reference. The base class has
certain XML attributes that are inherited in my derived class and are
printed on the properties when trying to serialize the object. How can I
get rid of them in the derived class (without modifying the base class)?
Testcase:
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
namespace XmlNamespaceProblem
{
[System.Xml.Serialization.XmlInclude(typeof(DerivedClass))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml",
"2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace =
"http://tempuri.org/TerminalUpdatesInformation.xsd")]
public class ClassFromWS
{
private string nameField;
private string descriptionField;
/// <remarks/>
public string Name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
}
}
/// <remarks/>
public string Description
{
get
{
return this.descriptionField;
}
set
{
this.descriptionField = value;
}
}
}
public class DerivedClass : ClassFromWS
{
private int iNewField;
public int NewPropery
{
get { return this.iNewField; }
set { this.iNewField = value; }
}
}
public class Program
{
public static void Main()
{
DerivedClass oObj = new DerivedClass();
oObj.Description = "hello...";
oObj.Name = "this is my name";
oObj.NewPropery = 15;
XmlSerializer oSer = new XmlSerializer(typeof(ClassFromWS));
TextWriter oWriter = new StreamWriter("classfromws.xml");
oSer.Serialize(oWriter, oObj);
oWriter.Close();
}
}
}
Current results:
<?xml version="1.0" encoding="utf-8"?>
<ClassFromWS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="DerivedClass">
<Name xmlns="http://tempuri.org/TerminalUpdatesInformation.xsd">this
is my name</Name>
<Description
xmlns="http://tempuri.org/TerminalUpdatesInformation.xsd">hello...</Description>
<NewPropery>15</NewPropery>
</ClassFromWS>
Expected result:
<?xml version="1.0" encoding="utf-8"?>
<ClassFromWS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="DerivedClass">
<Name>this is my name</Name>
<Description>hello...</Description>
<NewPropery>15</NewPropery>
</ClassFromWS>
or
<?xml version="1.0" encoding="utf-8"?>
<ClassFromWS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="DerivedClass"
xmlns="http://tempuri.org/TerminalUpdatesInformation.xsd">
<Name>this is my name</Name>
<Description>hello...</Description>
<NewPropery>15</NewPropery>
</ClassFromWS>
Thanks in advance!
Regards,
Andrés [ knocte ]
--
I am creating a class that is derived from one that comes from an
auto-generated code from a webservice reference. The base class has
certain XML attributes that are inherited in my derived class and are
printed on the properties when trying to serialize the object. How can I
get rid of them in the derived class (without modifying the base class)?
Testcase:
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
namespace XmlNamespaceProblem
{
[System.Xml.Serialization.XmlInclude(typeof(DerivedClass))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml",
"2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace =
"http://tempuri.org/TerminalUpdatesInformation.xsd")]
public class ClassFromWS
{
private string nameField;
private string descriptionField;
/// <remarks/>
public string Name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
}
}
/// <remarks/>
public string Description
{
get
{
return this.descriptionField;
}
set
{
this.descriptionField = value;
}
}
}
public class DerivedClass : ClassFromWS
{
private int iNewField;
public int NewPropery
{
get { return this.iNewField; }
set { this.iNewField = value; }
}
}
public class Program
{
public static void Main()
{
DerivedClass oObj = new DerivedClass();
oObj.Description = "hello...";
oObj.Name = "this is my name";
oObj.NewPropery = 15;
XmlSerializer oSer = new XmlSerializer(typeof(ClassFromWS));
TextWriter oWriter = new StreamWriter("classfromws.xml");
oSer.Serialize(oWriter, oObj);
oWriter.Close();
}
}
}
Current results:
<?xml version="1.0" encoding="utf-8"?>
<ClassFromWS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="DerivedClass">
<Name xmlns="http://tempuri.org/TerminalUpdatesInformation.xsd">this
is my name</Name>
<Description
xmlns="http://tempuri.org/TerminalUpdatesInformation.xsd">hello...</Description>
<NewPropery>15</NewPropery>
</ClassFromWS>
Expected result:
<?xml version="1.0" encoding="utf-8"?>
<ClassFromWS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="DerivedClass">
<Name>this is my name</Name>
<Description>hello...</Description>
<NewPropery>15</NewPropery>
</ClassFromWS>
or
<?xml version="1.0" encoding="utf-8"?>
<ClassFromWS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="DerivedClass"
xmlns="http://tempuri.org/TerminalUpdatesInformation.xsd">
<Name>this is my name</Name>
<Description>hello...</Description>
<NewPropery>15</NewPropery>
</ClassFromWS>
Thanks in advance!
Regards,
Andrés [ knocte ]
--