Defining Attributes

What is an Attribute?

Simple elements cannot have attributes. If an element has attributes, it is considered to be of a complex type. But the attribute itself is always declared as a simple type.

How to Define an Attribute?

The syntax for defining an attribute is:

Image 1

where xxx is the name of the attribute and yyy specifies the data type of the attribute.

XML Schema has a lot of built-in data types. The most common types are:

  • xs:string
  • xs:decimal
  • xs:integer
  • xs:boolean
  • xs:date
  • xs:time

Example

Here is an XML element with an attribute:

Image2

And here is the corresponding attribute definition:

Share this post
[social_warfare]
DTD
Defining Elements

Get industry recognized certification – Contact us

keyboard_arrow_up