Xsd Schema with include attribute as Embedded Resource RRS feed

  • Question

  • I'm setting my schemas files as Embedded Resource, here the code I tried:

     public MainWindow()
                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();
            private void ValidationEventHandler(object sender, ValidationEventArgs e)
                if (e.Severity == XmlSeverityType.Error)

    The schemas:

    <?xml version="1.0"?>
    <xsd:schema xmlns:xsd="">
      <xsd:include schemaLocation="TransmissionData_v2.00.xsd"/>
      <xsd:element name="Transmission" type="TransmissionHeaderXml"/>
      <xsd:complexType name="TransmissionHeaderXml">
          <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:attribute name="IsOffline" type="xsd:boolean" use="required"/>
        <xsd:attribute name="Status" type="TransmissionStatusXml" use="required"/>
      <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"/>

    <?xml version="1.0"?>
    <xsd:schema xmlns:xsd="">
      <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}\})"/>
    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

    Friday, May 31, 2013 9:18 PM


  • I don't normally embed schemas as resources but once you have the first schema embedded and you're successfully loading it into the document then it seems like you'd just repeat the process for the second schema.  So you'd load the first schema, add it to the document's Schemas collection, then load the second schema and add that to the document's Schemas collection.  Later when the document validates it will have access to both schemas.  I haven't tried it but it seems like it would work correctly.

    Michael Taylor

    Friday, May 31, 2013 10:22 PM