XML Schema tutorial
Post a reply

lesson6: XSD Complex Empty Elements

Fri Mar 06, 2009 12:20 am

XSD Complex Empty Elements:

In your XSD schema, you can define empty XSD complex element with no content.
xml code
<xs:element name="student">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="xs:integer">
<xs:attribute name="GPA" type="xs:positiveInteger"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>


The above Complex element type don't have any content elements.

xml code
<xs:element name="student">
<xs:complexType>
<xs:attribute name="GPA" type="xs:positiveInteger"/>
</xs:complexType>
</xs:element>

XML example:
xml code
<student GPA=3 />


Also remember, you can also can define you type by reference to complex type.
xml code
<xs:element name="student" type="studentType" />
<xs:complexType name="studentType" >
<xs:attribute name="GPA" type="xs:positiveInteger"/>
</xs:complexType>




Re: lesson6: XSD Complex Empty Elements

Mon Jan 09, 2012 2:46 pm

Using your first code snipped, I get this error on validation:

[Xerces-J 2.7.1] Validating "zzz-text.xml" against "file://zzz-text.xsd" ...
Ln 9 Col 45 - src-ct.1: Complex Type Definition Representation Error for type '#AnonType_studenttest'. When <complexContent> is used, the base type must be a complexType. 'integer' is a simpleType.
1 Errors

The second code is working. Should 'above' read 'below'?

Post a reply
  Related Posts  to : lesson6: XSD Complex Empty Elements
 lesson5: XSD Complex elements     -  
 lesson7: XSD Complex Text-Only Elements     -  
 Check empty string     -  
 check empty number     -  
 [Ajax/PHP] Registration - Check for empty textboxs     -  
 Complex Numbers     -  
 Complex numbers calculator (C++)     -  
 lesson9: XSD Complex Types Indicators     -  
 solve the complex numbers and do operations on it     -  
 lesson8: XSD Complex Type Mixed Content     -  

Topic Tags

XSD Elements