Q5M1 - XML Dudy Fathan Ali S.Kom
XML Schema
Q5M1 - XML
Dudy Fathan Ali, S.Kom (DFA)
2015
CEP - CCIT
Fakultas Teknik Universitas Indonesia
Declaring Attributes in a Schema
Q5M1 - XML Dudy Fathan Ali S.Kom
Attributes in an XML schema are declared in the same way as
elements.
Declaring attributes in an XML schema facilitates the assimilation of
information for an XML document.
Attribute declarations can be defined in two ways:
Simple type definitions: Facilitates local validation of the
attribute information.
Global attribute declarations: Enables reuse of attributes.
Attribute
Attribute Element
Q5M1 - XML Dudy Fathan Ali S.Kom
In XSD, an attribute for a user-defined element is declared
using the attribute element.
The syntax for declaring an attribute in XSD is:
<attribute name="attributename"
ref="attributename"
type="datatypename" use="value" value="value">
</attribute>
The attribute element contains attributes that are used to
further qualify and restrict the scope and usage of the user-
defined attribute.
Attribute Element
Q5M1 - XML Dudy Fathan Ali S.Kom
The attribute element consists of the following attributes:
name
ref
type
use
Attribute Element
Q5M1 - XML Dudy Fathan Ali S.Kom
The attribute element consists of the following attributes:
name
ref
type
use
Is used to specify the name of a user-defined attribute.
Must be used when the schema element is the parent
element of the attribute element.
Colon (:) should not be included in the value of the
name attribute.
Attribute Element
Q5M1 - XML Dudy Fathan Ali S.Kom
The attribute element consists of the following attributes:
name
ref
type
use
Is used to refer to a user-defined attribute declared either
in the same or in any other XSD document.
Attribute Element
Q5M1 - XML Dudy Fathan Ali S.Kom
The attribute element consists of the following attributes:
name
ref
type
use
Takes a value that specifies the data type of the user-
defined attribute.
<xsd:attribute name="PRODUCTID"
type="xsd:string">
OR
<xsd:attribute name="PRODID" type="myID">
Attribute Element
Q5M1 - XML Dudy Fathan Ali S.Kom
The attribute element consists of the following attributes:
name
ref
type
use Specifies the way in which an attribute can be used in an
XML document.
Values that can be assigned to the use attribute are
optional, default, required, and fixed.
<xsd:attribute name="baseprice“ type="xsd:integer“ use="optional" />
<xsd:attribute name="baseprice“ type="xsd:integer“ default="25" />
<xsd:attribute name="baseprice“ type="xsd:integer“ use="required" />
<xsd:attribute name="baseprice“ type="xsd:integer" fixed="600“ />
Attribute Element
Q5M1 - XML Dudy Fathan Ali S.Kom
Global Attribute
Q5M1 - XML Dudy Fathan Ali S.Kom
Global attributes are declared outside all element declarations.
Global attributes facilitate attribute reusability.
Global attributes can be associated with simple and complex
data types.
Global attributes have the schema element as the parent
element.
<xsd:schema>
<xsd:attribute name="NAME" type="xsd:string"/>
</xsd:schema>
Global Attribute
Q5M1 - XML Dudy Fathan Ali S.Kom
A global attribute can be reused from anywhere in a schema
<xsd:element name="BOOK" type="BOOKTYPE"/>
<xsd:complexType name="BOOKTYPE">
……..
<xsd:attribute ref="NAME"/>
……..
</xsd:complexType>
<xsd:element name="AUTHOR" type="AUTHORTYPE"/>
<xsd:complexType name="AUTHORTYPE">
……..
<xsd:attribute ref="NAME"/>
……..
</xsd:complexType>
Global Attribute
Q5M1 - XML Dudy Fathan Ali S.Kom
XSD Restrictions
Q5M1 - XML Dudy Fathan Ali S.Kom
In order to restrict values that can be assigned to an attribute
or element:
Declare the attribute or element and associate it with a user-
defined simple data type.
Create a simple data type by using the XSD simpleType
element.
Use the XSD restriction element within the simpleType
element to restrict the values that can be assigned to the
elements or attributes that use the simple data type.
Restricting Values
Q5M1 - XML Dudy Fathan Ali S.Kom
Example Code
Restrictions on Values
Q5M1 - XML Dudy Fathan Ali S.Kom
Consider of this following code, The following example defines an element called "age"
with a restriction. The value of age cannot be lower than 0 or greater than 150:
Restrictions on Values
Q5M1 - XML Dudy Fathan Ali S.Kom
Consider of this following code, The following example defines an element called "gender"
with a restriction. The only acceptable value is Male OR Female:
Restrictions for Datatypes
Q5M1 - XML Dudy Fathan Ali S.Kom
Source : w3schools.com
Q5M1 - XML Dudy Fathan Ali S.Kom
Thank You!
Dudy Fathan Ali S.Kom
dudy.fathan@eng.ui.ac.id

XML Schema Part 2

  • 1.
    Q5M1 - XMLDudy Fathan Ali S.Kom XML Schema Q5M1 - XML Dudy Fathan Ali, S.Kom (DFA) 2015 CEP - CCIT Fakultas Teknik Universitas Indonesia
  • 2.
    Declaring Attributes ina Schema Q5M1 - XML Dudy Fathan Ali S.Kom Attributes in an XML schema are declared in the same way as elements. Declaring attributes in an XML schema facilitates the assimilation of information for an XML document. Attribute declarations can be defined in two ways: Simple type definitions: Facilitates local validation of the attribute information. Global attribute declarations: Enables reuse of attributes. Attribute
  • 3.
    Attribute Element Q5M1 -XML Dudy Fathan Ali S.Kom In XSD, an attribute for a user-defined element is declared using the attribute element. The syntax for declaring an attribute in XSD is: <attribute name="attributename" ref="attributename" type="datatypename" use="value" value="value"> </attribute> The attribute element contains attributes that are used to further qualify and restrict the scope and usage of the user- defined attribute.
  • 4.
    Attribute Element Q5M1 -XML Dudy Fathan Ali S.Kom The attribute element consists of the following attributes: name ref type use
  • 5.
    Attribute Element Q5M1 -XML Dudy Fathan Ali S.Kom The attribute element consists of the following attributes: name ref type use Is used to specify the name of a user-defined attribute. Must be used when the schema element is the parent element of the attribute element. Colon (:) should not be included in the value of the name attribute.
  • 6.
    Attribute Element Q5M1 -XML Dudy Fathan Ali S.Kom The attribute element consists of the following attributes: name ref type use Is used to refer to a user-defined attribute declared either in the same or in any other XSD document.
  • 7.
    Attribute Element Q5M1 -XML Dudy Fathan Ali S.Kom The attribute element consists of the following attributes: name ref type use Takes a value that specifies the data type of the user- defined attribute. <xsd:attribute name="PRODUCTID" type="xsd:string"> OR <xsd:attribute name="PRODID" type="myID">
  • 8.
    Attribute Element Q5M1 -XML Dudy Fathan Ali S.Kom The attribute element consists of the following attributes: name ref type use Specifies the way in which an attribute can be used in an XML document. Values that can be assigned to the use attribute are optional, default, required, and fixed. <xsd:attribute name="baseprice“ type="xsd:integer“ use="optional" /> <xsd:attribute name="baseprice“ type="xsd:integer“ default="25" /> <xsd:attribute name="baseprice“ type="xsd:integer“ use="required" /> <xsd:attribute name="baseprice“ type="xsd:integer" fixed="600“ />
  • 9.
    Attribute Element Q5M1 -XML Dudy Fathan Ali S.Kom
  • 10.
    Global Attribute Q5M1 -XML Dudy Fathan Ali S.Kom Global attributes are declared outside all element declarations. Global attributes facilitate attribute reusability. Global attributes can be associated with simple and complex data types. Global attributes have the schema element as the parent element. <xsd:schema> <xsd:attribute name="NAME" type="xsd:string"/> </xsd:schema>
  • 11.
    Global Attribute Q5M1 -XML Dudy Fathan Ali S.Kom A global attribute can be reused from anywhere in a schema <xsd:element name="BOOK" type="BOOKTYPE"/> <xsd:complexType name="BOOKTYPE"> …….. <xsd:attribute ref="NAME"/> …….. </xsd:complexType> <xsd:element name="AUTHOR" type="AUTHORTYPE"/> <xsd:complexType name="AUTHORTYPE"> …….. <xsd:attribute ref="NAME"/> …….. </xsd:complexType>
  • 12.
    Global Attribute Q5M1 -XML Dudy Fathan Ali S.Kom
  • 13.
    XSD Restrictions Q5M1 -XML Dudy Fathan Ali S.Kom In order to restrict values that can be assigned to an attribute or element: Declare the attribute or element and associate it with a user- defined simple data type. Create a simple data type by using the XSD simpleType element. Use the XSD restriction element within the simpleType element to restrict the values that can be assigned to the elements or attributes that use the simple data type.
  • 14.
    Restricting Values Q5M1 -XML Dudy Fathan Ali S.Kom Example Code
  • 15.
    Restrictions on Values Q5M1- XML Dudy Fathan Ali S.Kom Consider of this following code, The following example defines an element called "age" with a restriction. The value of age cannot be lower than 0 or greater than 150:
  • 16.
    Restrictions on Values Q5M1- XML Dudy Fathan Ali S.Kom Consider of this following code, The following example defines an element called "gender" with a restriction. The only acceptable value is Male OR Female:
  • 17.
    Restrictions for Datatypes Q5M1- XML Dudy Fathan Ali S.Kom Source : w3schools.com
  • 18.
    Q5M1 - XMLDudy Fathan Ali S.Kom Thank You! Dudy Fathan Ali S.Kom [email protected]