#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    16
    Rep Power
    0

    How do I add an attribute to complex type in xsd?


    How can I add an attribute to the PersonType for age?
    Code:
    <complexType name="personType">
    	<sequence>
    	<element ref="ext:FirstName" minOccurs="1" maxOccurs="1"/>
    	<element ref="ext:LastName" minOccurs="1" maxOccurs="1"/>
    	</sequence>
    </complexType>
    
    <element name="LastName" type="string"/>
    <element name="FirstName" type = "nc:TextType"/>
    <element name="person"  type="ext:personType"/>
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,749
    Rep Power
    9397
    <attribute>
    Code:
    <complexType name="personType">
    	<sequence>
    		<element ref="ext:FirstName" minOccurs="1" maxOccurs="1"/>
    		<element ref="ext:LastName" minOccurs="1" maxOccurs="1"/>
    	</sequence>
    	<attribute name="age" type="integer"/>
    </complexType>
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    16
    Rep Power
    0
    That works just great. I had that attribute definition above the sequence but that failed. I have a lot to learn. Thanks.
  6. #4
  7. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,749
    Rep Power
    9397
    Originally Posted by groads2
    That works just great. I had that attribute definition above the sequence but that failed. I have a lot to learn. Thanks.
    XSD is strict about where elements may be placed; in a <complexType> the <sequence> must come before any <attribute>s.

    Though it pertains mostly to the .NET framework, the MSDN is a great source of general documentation.
    xsd:complexType
    If group, sequence, choice, or all is specified, the elements must appear in the following order.
    1. group | sequence | choice | all
    2. attribute | attributeGroup
    3. anyAttribute

IMN logo majestic logo threadwatch logo seochat tools logo