2 // System.Xml.Serialization.XmlSchemaExporterTests
5 // Gert Driesen (drieseng@users.sourceforge.net)
11 using System.Collections;
12 using System.Globalization;
15 using System.Xml.Schema;
16 using System.Xml.Serialization;
18 using NUnit.Framework;
20 using MonoTests.System.Xml.TestClasses;
22 namespace MonoTests.System.XmlSerialization
25 public class XmlSchemaExporterTests
28 [Category ("NotWorking")] // on Mono, element is output before type
29 public void ExportStruct ()
31 XmlReflectionImporter ri = new XmlReflectionImporter ("NSTimeSpan");
32 XmlSchemas schemas = new XmlSchemas ();
33 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
34 XmlTypeMapping tm = ri.ImportTypeMapping (typeof (TimeSpan));
35 sx.ExportTypeMapping (tm);
37 Assert.AreEqual (1, schemas.Count, "#1");
39 StringWriter sw = new StringWriter ();
40 schemas[0].Write (sw);
42 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
43 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
44 "<xs:schema xmlns:tns=\"NSTimeSpan\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpan\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
45 " <xs:element name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
46 " <xs:complexType name=\"TimeSpan\" />{0}" +
47 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
51 [Category ("NotWorking")] // on Mono, element is output before type
52 public void ExportStruct_Array ()
54 XmlReflectionImporter ri = new XmlReflectionImporter ("NSTimeSpanArray");
55 XmlSchemas schemas = new XmlSchemas ();
56 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
57 XmlTypeMapping tm = ri.ImportTypeMapping (typeof (TimeSpan[]));
58 sx.ExportTypeMapping (tm);
60 Assert.AreEqual (1, schemas.Count, "#1");
62 StringWriter sw = new StringWriter ();
63 schemas[0].Write (sw);
65 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
66 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
67 "<xs:schema xmlns:tns=\"NSTimeSpanArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpanArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
68 " <xs:element name=\"ArrayOfTimeSpan\" nillable=\"true\" type=\"tns:ArrayOfTimeSpan\" />{0}" +
69 " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
71 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
72 " </xs:sequence>{0}" +
73 " </xs:complexType>{0}" +
74 " <xs:complexType name=\"TimeSpan\" />{0}" +
75 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
79 [Category ("NotWorking")] // on Mono, element is output before type
80 public void ExportClass ()
82 XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
83 XmlAttributes attr = new XmlAttributes ();
84 XmlElementAttribute element = new XmlElementAttribute ();
85 element.ElementName = "saying";
86 element.IsNullable = true;
87 attr.XmlElements.Add (element);
88 overrides.Add (typeof (SimpleClass), "something", attr);
90 XmlReflectionImporter ri = new XmlReflectionImporter (overrides, "NS1");
91 XmlSchemas schemas = new XmlSchemas ();
92 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
93 XmlTypeMapping tm = ri.ImportTypeMapping (typeof (SimpleClass));
94 sx.ExportTypeMapping (tm);
96 Assert.AreEqual (1, schemas.Count, "#1");
98 StringWriter sw = new StringWriter ();
99 schemas[0].Write (sw);
101 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
102 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
103 "<xs:schema xmlns:tns=\"NS1\" elementFormDefault=\"qualified\" targetNamespace=\"NS1\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
104 " <xs:element name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
105 " <xs:complexType name=\"SimpleClass\">{0}" +
106 " <xs:sequence>{0}" +
107 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
108 " </xs:sequence>{0}" +
109 " </xs:complexType>{0}" +
110 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
114 [Category ("NotWorking")] // on Mono, element is output before type
115 public void ExportClass_Array ()
117 XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
118 XmlAttributes attr = new XmlAttributes ();
119 XmlElementAttribute element = new XmlElementAttribute ();
120 element.ElementName = "saying";
121 element.IsNullable = true;
122 attr.XmlElements.Add (element);
123 overrides.Add (typeof (SimpleClass), "something", attr);
125 XmlReflectionImporter ri = new XmlReflectionImporter (overrides, "NSSimpleClassArray");
126 XmlSchemas schemas = new XmlSchemas ();
127 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
128 XmlTypeMapping tm = ri.ImportTypeMapping (typeof (SimpleClass[]));
129 sx.ExportTypeMapping (tm);
131 Assert.AreEqual (1, schemas.Count, "#1");
133 StringWriter sw = new StringWriter ();
134 schemas[0].Write (sw);
136 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
137 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
138 "<xs:schema xmlns:tns=\"NSSimpleClassArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
139 " <xs:element name=\"ArrayOfSimpleClass\" nillable=\"true\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
140 " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
141 " <xs:sequence>{0}" +
142 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
143 " </xs:sequence>{0}" +
144 " </xs:complexType>{0}" +
145 " <xs:complexType name=\"SimpleClass\">{0}" +
146 " <xs:sequence>{0}" +
147 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
148 " </xs:sequence>{0}" +
149 " </xs:complexType>{0}" +
150 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
154 [Category ("NotWorking")] // on Mono, element is output before type
155 public void ExportEnum ()
157 XmlReflectionImporter ri = new XmlReflectionImporter ("NS2");
158 XmlSchemas schemas = new XmlSchemas ();
159 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
160 XmlTypeMapping tm = ri.ImportTypeMapping (typeof (EnumDefaultValue));
161 sx.ExportTypeMapping (tm);
163 Assert.AreEqual (1, schemas.Count, "#1");
165 StringWriter sw = new StringWriter ();
166 schemas[0].Write (sw);
168 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
169 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
170 "<xs:schema xmlns:tns=\"NS2\" elementFormDefault=\"qualified\" targetNamespace=\"NS2\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
171 " <xs:element name=\"EnumDefaultValue\" type=\"tns:EnumDefaultValue\" />{0}" +
172 " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
174 " <xs:simpleType>{0}" +
175 " <xs:restriction base=\"xs:string\">{0}" +
176 " <xs:enumeration value=\"e1\" />{0}" +
177 " <xs:enumeration value=\"e2\" />{0}" +
178 " <xs:enumeration value=\"e3\" />{0}" +
179 " </xs:restriction>{0}" +
180 " </xs:simpleType>{0}" +
182 " </xs:simpleType>{0}" +
183 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
187 [Category ("NotWorking")] // on Mono, element is output before type
188 public void ExportXmlSerializable ()
190 XmlReflectionImporter ri = new XmlReflectionImporter ("NS3");
191 XmlSchemas schemas = new XmlSchemas ();
192 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
193 XmlTypeMapping tm = ri.ImportTypeMapping (typeof (Employee));
194 sx.ExportTypeMapping (tm);
196 Assert.AreEqual (1, schemas.Count, "#1");
198 StringWriter sw = new StringWriter ();
199 schemas[0].Write (sw);
201 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
202 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
203 "<xs:schema xmlns:tns=\"NS3\" elementFormDefault=\"qualified\" targetNamespace=\"NS3\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
204 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
205 " <xs:element name=\"Employee\" nillable=\"true\">{0}" +
206 " <xs:complexType>{0}" +
207 " <xs:sequence>{0}" +
208 " <xs:element ref=\"xs:schema\" />{0}" +
210 " </xs:sequence>{0}" +
211 " </xs:complexType>{0}" +
212 " </xs:element>{0}" +
213 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
215 ri = new XmlReflectionImporter ("NS4");
217 schemas = new XmlSchemas ();
218 sx = new XmlSchemaExporter (schemas);
219 tm = ri.ImportTypeMapping (typeof (EmployeeSchema));
220 sx.ExportTypeMapping (tm);
222 Assert.AreEqual (1, schemas.Count, "#3");
224 sw = new StringWriter ();
225 schemas[0].Write (sw);
227 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
228 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
229 "<xs:schema xmlns:tns=\"NS4\" elementFormDefault=\"qualified\" targetNamespace=\"NS4\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
231 " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
232 " <xs:element name=\"employeeRoot\" nillable=\"true\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
234 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
235 " <xs:element name=\"EmployeeSchema\" nillable=\"true\">{0}" +
236 " <xs:complexType>{0}" +
237 " <xs:sequence>{0}" +
238 " <xs:element ref=\"xs:schema\" />{0}" +
240 " </xs:sequence>{0}" +
241 " </xs:complexType>{0}" +
242 " </xs:element>{0}" +
244 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
248 [Category ("NotWorking")] // bug #77117
249 public void ExportXsdPrimitive ()
251 ArrayList types = new ArrayList ();
252 types.Add (new TypeDescription (typeof (byte), true, "unsignedByte", "Byte"));
253 types.Add (new TypeDescription (typeof (sbyte), true, "byte", "Byte"));
254 types.Add (new TypeDescription (typeof (bool), true, "boolean", "Boolean"));
255 types.Add (new TypeDescription (typeof (short), true, "short", "Short"));
256 types.Add (new TypeDescription (typeof (int), true, "int", "Int"));
257 types.Add (new TypeDescription (typeof (long), true, "long", "Long"));
258 types.Add (new TypeDescription (typeof (float), true, "float", "Float"));
259 types.Add (new TypeDescription (typeof (double), true, "double", "Double"));
260 types.Add (new TypeDescription (typeof (decimal), true, "decimal", "Decimal"));
261 types.Add (new TypeDescription (typeof (ushort), true, "unsignedShort", "UnsignedShort"));
262 types.Add (new TypeDescription (typeof (uint), true, "unsignedInt", "UnsignedInt"));
263 types.Add (new TypeDescription (typeof (ulong), true, "unsignedLong", "UnsignedLong"));
264 types.Add (new TypeDescription (typeof (DateTime), true, "dateTime", "DateTime"));
266 types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName", true));
268 types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName"));
270 types.Add (new TypeDescription (typeof (string), true, "string", "String", true));
272 foreach (TypeDescription typeDesc in types) {
273 XmlReflectionImporter ri = new XmlReflectionImporter (typeDesc.Type.Name);
274 XmlSchemas schemas = new XmlSchemas ();
275 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
276 XmlTypeMapping tm = ri.ImportTypeMapping (typeDesc.Type);
277 sx.ExportTypeMapping (tm);
279 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
281 StringWriter sw = new StringWriter ();
282 schemas[0].Write (sw);
284 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
285 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
286 "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
287 " <xs:element name=\"{2}\" {3}type=\"xs:{2}\" />{0}" +
288 "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.XmlType, typeDesc.IsNillable ? "nillable=\"true\" " : ""),
289 sw.ToString (), typeDesc.Type.FullName + "#2");
294 [Category ("NotWorking")] // bug #77117
295 public void ExportXsdPrimitive_ByteArray ()
297 XmlReflectionImporter ri = new XmlReflectionImporter ("ByteArray");
298 XmlSchemas schemas = new XmlSchemas ();
299 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
300 XmlTypeMapping tm = ri.ImportTypeMapping (typeof (byte[]));
301 sx.ExportTypeMapping (tm);
303 Assert.AreEqual (1, schemas.Count, "#1");
305 StringWriter sw = new StringWriter ();
306 schemas[0].Write (sw);
308 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
309 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
310 "<xs:schema xmlns:tns=\"ByteArray\" elementFormDefault=\"qualified\" targetNamespace=\"ByteArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
311 " <xs:element name=\"base64Binary\" nillable=\"true\" type=\"xs:base64Binary\" />{0}" +
312 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
316 [Category ("NotWorking")] // bug #77117
317 public void ExportXsdPrimitive_Arrays ()
319 ArrayList types = new ArrayList ();
320 types.Add (new TypeDescription (typeof (sbyte[]), true, "byte", "Byte"));
321 types.Add (new TypeDescription (typeof (bool[]), true, "boolean", "Boolean"));
322 types.Add (new TypeDescription (typeof (short[]), true, "short", "Short"));
323 types.Add (new TypeDescription (typeof (int[]), true, "int", "Int"));
324 types.Add (new TypeDescription (typeof (long[]), true, "long", "Long"));
325 types.Add (new TypeDescription (typeof (float[]), true, "float", "Float"));
326 types.Add (new TypeDescription (typeof (double[]), true, "double", "Double"));
327 types.Add (new TypeDescription (typeof (decimal[]), true, "decimal", "Decimal"));
328 types.Add (new TypeDescription (typeof (ushort[]), true, "unsignedShort", "UnsignedShort"));
329 types.Add (new TypeDescription (typeof (uint[]), true, "unsignedInt", "UnsignedInt"));
330 types.Add (new TypeDescription (typeof (ulong[]), true, "unsignedLong", "UnsignedLong"));
331 types.Add (new TypeDescription (typeof (DateTime[]), true, "dateTime", "DateTime"));
333 types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName", true));
335 types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName"));
337 types.Add (new TypeDescription (typeof (string[]), true, "string", "String", true));
339 foreach (TypeDescription typeDesc in types) {
340 XmlReflectionImporter ri = new XmlReflectionImporter (typeDesc.Type.Name);
341 XmlSchemas schemas = new XmlSchemas ();
342 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
343 XmlTypeMapping tm = ri.ImportTypeMapping (typeDesc.Type);
344 sx.ExportTypeMapping (tm);
346 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
348 StringWriter sw = new StringWriter ();
349 schemas[0].Write (sw);
351 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
352 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
353 "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
354 " <xs:element name=\"ArrayOf{2}\" nillable=\"true\" type=\"tns:ArrayOf{2}\" />{0}" +
355 " <xs:complexType name=\"ArrayOf{2}\">{0}" +
356 " <xs:sequence>{0}" +
357 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"{3}\" {5}type=\"{4}:{3}\" />{0}" +
358 " </xs:sequence>{0}" +
359 " </xs:complexType>{0}" +
360 "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.ArrayType, typeDesc.XmlType,
361 typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : ""),
362 sw.ToString (), typeDesc.Type.FullName + "#2");
367 [Category ("NotWorking")] // bug #77117
368 public void ExportNonXsdPrimitive_Guid ()
370 XmlReflectionImporter ri = new XmlReflectionImporter ("NSPrimGuid");
371 XmlSchemas schemas = new XmlSchemas ();
372 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
373 XmlTypeMapping tm = ri.ImportTypeMapping (typeof (Guid));
374 sx.ExportTypeMapping (tm);
376 Assert.AreEqual (2, schemas.Count, "#1");
378 StringWriter sw = new StringWriter ();
379 schemas[0].Write (sw);
381 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
382 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
383 "<xs:schema xmlns:tns=\"NSPrimGuid\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimGuid\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
384 " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
385 " <xs:element name=\"guid\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:guid\" />{0}" +
386 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
388 sw = new StringWriter ();
389 schemas[1].Write (sw);
391 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
392 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
393 "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" elementFormDefault=\"qualified\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
394 " <xs:simpleType name=\"guid\">{0}" +
395 " <xs:restriction base=\"xs:string\">{0}" +
396 " <xs:pattern value=\"[0-9a-fA-F]{{8}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{12}}\" />{0}" +
397 " </xs:restriction>{0}" +
398 " </xs:simpleType>{0}" +
399 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
403 [Category ("NotWorking")] // bug #77117
404 public void ExportNonXsdPrimitive_Char ()
406 XmlReflectionImporter ri = new XmlReflectionImporter ("NSPrimChar");
407 XmlSchemas schemas = new XmlSchemas ();
408 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
409 XmlTypeMapping tm = ri.ImportTypeMapping (typeof (Char));
410 sx.ExportTypeMapping (tm);
412 Assert.AreEqual (2, schemas.Count, "#1");
414 StringWriter sw = new StringWriter ();
415 schemas[0].Write (sw);
417 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
418 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
419 "<xs:schema xmlns:tns=\"NSPrimChar\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimChar\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
420 " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
421 " <xs:element name=\"char\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:char\" />{0}" +
422 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
424 sw = new StringWriter ();
425 schemas[1].Write (sw);
427 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
428 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
429 "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" elementFormDefault=\"qualified\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
430 " <xs:simpleType name=\"char\">{0}" +
431 " <xs:restriction base=\"xs:unsignedShort\" />{0}" +
432 " </xs:simpleType>{0}" +
433 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
436 public class Employee : IXmlSerializable
438 private string _firstName;
439 private string _lastName;
440 private string _address;
442 public XmlSchema GetSchema ()
447 public void WriteXml (XmlWriter writer)
449 writer.WriteStartElement ("employee", "urn:devx-com");
450 writer.WriteAttributeString ("firstName", _firstName);
451 writer.WriteAttributeString ("lastName", _lastName);
452 writer.WriteAttributeString ("address", _address);
453 writer.WriteEndElement ();
456 public void ReadXml (XmlReader reader)
458 XmlNodeType type = reader.MoveToContent ();
459 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
460 _firstName = reader["firstName"];
461 _lastName = reader["lastName"];
462 _address = reader["address"];
468 [XmlSchemaProvider ("CreateEmployeeSchema")]
470 public class EmployeeSchema : Employee
473 public static XmlQualifiedName CreateEmployeeSchema (XmlSchemaSet schemaSet)
475 XmlSchema schema = new XmlSchema();
476 schema.Id = "EmployeeSchema";
477 schema.TargetNamespace = "urn:types-devx-com";
479 XmlSchemaComplexType type = new XmlSchemaComplexType();
480 type.Name = "employeeRoot";
481 XmlSchemaAttribute firstNameAttr = new XmlSchemaAttribute();
482 firstNameAttr.Name = "firstName";
483 type.Attributes.Add(firstNameAttr);
485 XmlSchemaAttribute lastNameAttr = new XmlSchemaAttribute();
486 lastNameAttr.Name = "lastName";
487 type.Attributes.Add(lastNameAttr);
489 XmlSchemaAttribute addressAttr = new XmlSchemaAttribute();
490 addressAttr.Name = "address";
491 type.Attributes.Add(addressAttr);
493 XmlSchemaElement employeeElement = new XmlSchemaElement();
494 employeeElement.Name = "employee";
495 XmlQualifiedName name = new XmlQualifiedName("employeeRoot", "urn:types-devx-com");
496 employeeElement.SchemaTypeName = name;
498 schema.Items.Add(type);
499 schema.Items.Add(employeeElement);
500 schemaSet.Add(schema);
506 private class TypeDescription
508 public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType) : this (type, xsdType, xmlType, arrayType, false)
512 public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType, bool isNillable)
517 _arrayType = arrayType;
518 _isNillable = isNillable;
522 get { return _type; }
525 public string XmlType {
526 get { return _xmlType; }
529 public string ArrayType {
530 get { return _arrayType; }
533 public bool XsdType {
534 get { return _xsdType; }
537 public bool IsNillable {
538 get { return _isNillable; }
542 private bool _xsdType;
543 private string _xmlType;
544 private string _arrayType;
545 private bool _isNillable;