Answered xsd:redefine not supported

  • Thursday, May 17, 2012 3:41 PM
     
     

    Hello.  I looked through the Related Topics and didn't see the answer I was looking for.

    I received some XML Schemas from a 3rd party that has xsd:redefines in some of the include files.

    Is there a .NET tool that will support the xsd:redefine tag and will generate classes?

    If not, then I need to modify the xsd's to eliminate the xsd:redefine.

    My redefine snippet is as follows:

    <xsd:redefine schemaLocation="Old.xsd">
      <xsd:complexType name="My_Type">
        <xsd:complexContent>
          <xsd:extension base="My_Type">
            <xsd:sequence>
              <xsd:element ref="IT:Token" minOccurs="0" />
              <xsd:element ref="IT:Principal" maxOccurs="unbounded" minOccurs="0" />
              <xsd:element ref="IT:Trust" minOccurs="0" />
            </xsd:sequence>
          </xsd:extension>
      </xsd:complexContent>
    </xsd:complexType>

    In Old.xsd, I have the following snippet:

    <xsd:complexType name="My_Type">
        <xsd:sequence>
            <xsd:element name="MyAuthentication" type="MyAuthentication_Type" nillable="true" />
            <xsd:element name="PrincipalID" type="xsd:string" nillable="true" />
        </xsd:sequence>
    </xsd:complexType>

    Do I simply extend Old.xsd by adding the redefine elements?  Or, do I replace MyAuthentication and PrincipalID with the redefine elements?

    <xsd:complexType name="My_Type">
        <xsd:sequence>
            <xsd:element name="MyAuthentication" type="MyAuthentication_Type" nillable="true" />
            <xsd:element name="PrincipalID" type="xsd:string" nillable="true" />
            <xsd:element ref="IT:Token" minOccurs="0" />
            <xsd:element ref="IT:Principal" maxOccurs="unbounded" minOccurs="0" />
            <xsd:element ref="IT:Trust" minOccurs="0" />
        </xsd:sequence>
    </xsd:complexType>

    or

    <xsd:complexType name="My_Type">
        <xsd:sequence>
            <xsd:element ref="IT:Token" minOccurs="0" />
            <xsd:element ref="IT:Principal" maxOccurs="unbounded" minOccurs="0" />
            <xsd:element ref="IT:Trust" minOccurs="0" />
        </xsd:sequence>
    </xsd:complexType>

     

    Thanks!!!

All Replies

  • Friday, May 18, 2012 6:43 AM
    Moderator
     
     
    According to http://msdn.microsoft.com/en-us/library/xsayb845(v=vs.100).aspx, xsd.exe does not support redefine. If you use XmlSerializer, you have to modify the schema to remove the redefine. DataContractSerializer doesn't support redefine, either.

    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    If you have feedback about forum business, please contact msdnmg@microsoft.com. But please do not ask technical questions in the email.

  • Friday, May 18, 2012 7:41 AM
     
     

    Hi,

    You can try XSD2Code which is available in code plex.

    http://xsd2code.codeplex.com/


    Welcome to MSDN Forums. Feel free to ask your questions and Please Note to Vote helpful topics and Mark answering posts. Sudhakar

  • Friday, May 18, 2012 2:30 PM
     
     
    Thanks Sudhakar.  XSD2Code doesn't support the xsd: redefine either.
  • Friday, May 18, 2012 2:31 PM
     
     Answered
    Thanks Yi-Lun.  I am modifying the schema to remove the redefines.
  • Friday, August 17, 2012 2:11 PM
     
     

    Is there a good pattern to use for removing the redefines?  I'm trying to generate classes for the OpenCDISC Validator config XSD but they have a complicated XSD hierarchy using redefines for extension of elements.  And they all use Java, so it's apparently no problem for them. 

    My question on the OpenCDISC forum: http://www.opencdisc.org/forum/validator-xsd-c-classes-xsdexe

  • Friday, August 17, 2012 3:50 PM
     
     

    Hi CuppM.  I didn't find anything to help me.  I ended up having to do it all by hand.  And, I can feel your pain from the complicated XSD hierarchy.  Hope someone else can provide a more satisfactory response.

    Thanks!

  • Friday, August 17, 2012 4:59 PM
     
     
    I think I eventually figured it out.  Basically commented out the original definitions so only the most extended definitions were left uncommented.  Then it generated w/o warnings or errors.  Hacky but workss.