Total members 11895 |It is currently Tue Dec 03, 2024 5:49 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





XSD Attributes :
XSD Attributes is used only with complex types .The declaration of attribute is like simple types. In declaration you define attribute name and type.

Example on attribute declaration:
<xs:attribute name="mydate" type="date"/>

Type can be :
- xs:boolean
- xs:date
- xs:time
- xs:string
- xs:decimal
- xs:integer


Example on attribute usage:

<xs:attribute name="mydate" type="xs:date"/>
This XSD code defines an attribute called "mydate" with a specific data type of "xs:date". xs:date is a built-in data type from the XML Schema standard. It represents a date without a time-zone. The format of the date should be in the form of "yyyy-mm-dd" where "yyyy" is the 4 digits year, "mm" is the 2 digits month and "dd" is the 2 digits day. This attribute can be added to an element in an XML document and it can only contain a date value in the format specified above.


Xml is:
Code:
<event mydate="1-1-2009">New customer</event>


The default value for attributes:
Code:
<xs:attribute name="mydate" type="xs:date default="0-0-0000" />


In this XSD code, the attribute "mydate" has a default value of "0-0-0000" which will be used in case the attribute is not present in the XML.
If the attribute is present in the XML but its value is not a valid date, an error will be raised. It's important to notice that this default value "0-0-0000" is not a valid date according to the format "yyyy-mm-dd". It is used as a placeholder or a way to indicate that the date is not provided or not known.


The default value is the value that the attribute takes when you don't specify any values.
Fixed value for attributes:
Code:
<xs:attribute name="mydate" type="xs:date" fixed="0-0-0000" />

This XSD code <xs:attribute name="mydate" type="xs:date" fixed="0-0-0000" />, defines an attribute called "mydate" with a data type of "xs:date" and with a fixed value "0-0-0000". This means that the attribute must always have the value "0-0-0000" in the corresponding XML document, and it cannot be changed by a user or application.



Required attributes:
To ensure that the attribute will exist in the element you use required.
Code:
<xs:attribute name="mydate" type="xs:date" use="required" />


This XSD code defines an attribute called "mydate" with a specific data type of "xs:date" and with a use value of "required". This means that the attribute must be present in the corresponding XML document and it must contain a valid date in the format "yyyy-mm-dd". If the attribute is not present, or its value is not a valid date an error will be raised.



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


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : lesson3 :XSD Attributes
 change link <a> attributes dynamically     -  
 get HTML elements attributes values using JQuery     -  



Topic Tags

XSD Attributes






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