I'm setting my schemas files as Embedded Resource, here the code I tried:
public MainWindow() { InitializeComponent(); var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WpfApplication1.TransmissionHeader_v1.00.xsd"); var xml = File.OpenRead("Header.xml"); ReadSchema(stream, xml); } private void ReadSchema(Stream XsdFile, Stream XmlFile) { var xmlSchema = XmlSchema.Read(XsdFile, null); XsdFile.Position = 0; var xmlDocument = new XmlDocument(); xmlDocument.Load(XmlFile); xmlDocument.Schemas.Add(xmlSchema); xmlDocument.Validate(ValidationEventHandler); } private void ValidationEventHandler(object sender, ValidationEventArgs e) { if (e.Severity == XmlSeverityType.Error) { } }
The schemas:
<?xml version="1.0"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"><xsd:include schemaLocation="TransmissionData_v2.00.xsd"/><xsd:element name="Transmission" type="TransmissionHeaderXml"/><xsd:complexType name="TransmissionHeaderXml"><xsd:sequence><xsd:element name="Id" nillable="true" type="xsd:int"/><xsd:element name="Name" nillable="false" type="xsd:string"/><xsd:element name="Date" nillable="false" type="xsd:dateTime"/><xsd:element name="LastTransmitedOn" nillable="true" type="xsd:dateTime"/><xsd:element name="Teste" nillable="true" type="Guid"/></xsd:sequence><xsd:attribute name="IsOffline" type="xsd:boolean" use="required"/><xsd:attribute name="Status" type="TransmissionStatusXml" use="required"/></xsd:complexType><xsd:simpleType name="TransmissionStatusXml"><xsd:restriction base="xsd:string"><xsd:enumeration value="OnDemand"/><xsd:enumeration value="StandBy"/><xsd:enumeration value="Live"/><xsd:enumeration value="Suspended"/><xsd:enumeration value="Finished"/></xsd:restriction></xsd:simpleType></xsd:schema>
<?xml version="1.0"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"><xsd:simpleType name="Guid"><xsd:restriction base="xsd:string"><xsd: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-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\})"/></xsd:restriction></xsd:simpleType></xsd:schema>As you can see, I'm including one Schema in another, but how can I get both as embedded resource?
And here's the following error:
Type 'Guid' is not declared.
Take a look at WPF FlashMessage
About.me