Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" encoding="utf-8"?>
- <xs:schema targetNamespace="fred" elementFormDefault="qualified" xmlns="fred" xmlns:mstns="http://tempuri.org/XMLSchema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
- <xs:element name="Devices">
- <xs:complexType>
- <xs:sequence>
- <xs:element maxOccurs="unbounded" name="device" />
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- </xs:schema>
Expand|Select|Wrap|Line Numbers
- [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
- [System.SerializableAttribute()]
- [System.Diagnostics.DebuggerStepThroughAttribute()]
- [System.ComponentModel.DesignerCategoryAttribute("code")]
- [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="fred")]
- [System.Xml.Serialization.XmlRootAttribute(Namespace="fred", IsNullable=false)]
- public partial class Devices {
- private object[] deviceField;
- /// <remarks/>
- [System.Xml.Serialization.XmlElementAttribute("device")]
- public object[] device {
- get {
- return this.deviceField;
- }
- set {
- this.deviceField = value;
- }
- }
- }
My deserializer code:
Expand|Select|Wrap|Line Numbers
- XmlReaderSettings deviceSettings = new XmlReaderSettings();
- deviceSettings.Schemas.Add("fred", "DeviceConfigration.xsd");
- deviceSettings.ValidationType = ValidationType.Schema;
- deviceSettings.IgnoreWhitespace = true;
- deviceSettings.ValidationEventHandler += new ValidationEventHandler(booksSettingsValidationEventHandler);
- XmlReader reader = XmlReader.Create("DeviceConfiguration.xml", deviceSettings);
- XmlSerializer serializer = new XmlSerializer(typeof(Devices));
- Devices devices;
- try
- {
- devices = (Devices)serializer.Deserialize(reader);
- }
- catch (Exception ex)
- {
- return;
- }
This is whether I add the missing name or not.