Total members 11893 |It is currently Fri Nov 15, 2024 9:35 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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>


This XSD snippet defines an XML element called "student" with a complex type consisting of an integer data type restriction. The restriction has an attribute called "GPA" of the data type "xs:positiveInteger". This means that the "student" element must contain an integer value, and it can also have an attribute called "GPA" that must contain a positive integer value. It is worth noting that this XSD snippet only defines the structure of the "student" element, it doesn't specify any rules or constraints on how many times the element can occur, where it can occur in the XML document, or what elements can come before or after it. If you want to specify these kinds of rules, you would need to include the "student" element in a larger XSD schema that defines the overall structure of the XML document. You can also specify the default value and fixed values for the attribute "GPA" by using the default and fixed attributes in the xs:attribute element.


The above Complex element type doesn'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>




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

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'?


Author:
Post new topic Reply to topic  [ 2 posts ] 

  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
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com