Hi, I am begginer and I have one problem. I read tutorial about Customizing XML Serialization with IXmlSerializable from
http://www.c-sharpcorner.com/UploadFile/prvn_131971/WebServiceStandardsandExtensions02072008073635AM/WebServiceStandardsandExtensions.aspx
Class which is serialize :
public class EmployeeDetailsCustom : IXmlSerializable
{
public int ID;
public string FirstName;
public string LastName;
const string ns = "http://www.apress.com/ProASP.NET/CustomEmployeeDetails";
void IXmlSerializable.WriteXml(XmlWriter w)
{
w.WriteStartElement("Employee", ns);
w.WriteStartElement("Name", ns);
w.WriteElementString("First", ns, FirstName);
w.WriteElementString("Last", ns, LastName);
w.WriteEndElement();
w.WriteElementString("ID", ns, ID.ToString());
w.WriteEndElement();
}
void IXmlSerializable.ReadXml(XmlReader r)
{
r.MoveToContent();
r.ReadStartElement("Employee");
r.ReadStartElement("Name");
FirstName = r.ReadElementString("First", ns);
LastName = r.ReadElementString("Last", ns);
r.ReadEndElement();
r.MoveToContent();
ID = Int32.Parse(r.ReadElementString("ID", ns));
reader.ReadEndElement();
}
System.Xml.Schema.XmlSchema IXmlSerializable.GetSchema()
{
return null;
}
// (Constructors omitted.)
}
Method which return XML scheme as XmlQualifiedName object .
public static XmlQualifiedName GetSchemaDocument(XmlSchemaSet xs)
{
// Get the path to the schema file.
string schemaPath = HttpContext.Current.Server.MapPath("EmployeeDetails.xsd");
// Retrieve the schema from the file.
XmlSerializer schemaSerializer = new XmlSerializer(typeof(XmlSchema));
XmlSchema s = (XmlSchema)schemaSerializer.Deserialize(new XmlTextReader(schemaPath), null);
xs.XmlResolver = new XmlUrlResolver();
xs.Add(s);
return new XmlQualifiedName("EmployeeDetails", ns);
}
Implementation on web method.
[XmlSchemaProvider("GetSchemaDocument")]
public class EmployeeDetailsCustom : IXmlSerializable
{ ... }
The method public static XmlQualifiedName GetSchemaDocument load xml scheme from file. My question is how can I get xml scheme from my own object. It must be wrote be me , or can be generated with some utility or object from .NET ?
What is the simple way how get xml scheme from my own object. Thank..