جستجو در محصولات

گالری پروژه های افتر افکت
گالری پروژه های PSD
جستجو در محصولات


تبلیغ بانک ها در صفحات
ربات ساز تلگرام در صفحات
ایمن نیوز در صفحات
.. سیستم ارسال پیامک ..
XSD چيست ؟( بخش ششم)
-(47 Body) 
XSD چيست ؟( بخش ششم)
Visitor 892
Category: کامپيوتر
در اين بخش به بررسي  انواع داده در XSD  ، خواهيم پرداخت .
تعيين نوع داده  يکي از ويژگي هاي مهم XSD بوده  که با استفاده از آن ميتوان عناصر و يا خصلت ها را با فرمت صحيح و دلخواه اعتبار سنجي نمود . تکنولوژي  XSD ، دامنه گسترده و وسيعي از  انواع داده را حمايت و در عين حال  به کاربر امکان تعريف نوع داده دلخواه را نيز خواهد داد .

انواع داده ساده يا استاندارد
تکنولوژي XSD ، يش از چهل و چهار نوع نوع داده ساده يا استاندارد را حمايت که  بسياري از آنان بصورت از پيش تعريف شده در XSD تعبيه  و برخي ديگر نيز از تعاريف فوق ، مشتق شده اند . بدين ترتيب کاربران بسادگي  قادر به استفاده از آنان  در توصيف عناصر و يا خصلت هاي اسناد مورد نظر خود خواهند بود  .
جدول زير ، نحوه تعريف نوع داده يک عنصر را نشان مي دهد ( در بخش هاي قبل مقالات از آن استفاده شده است ) .

تعريف يک نوع داده در XSD

     .
     .
    
.
 <XSD:Element Name="ID"      Type="XSD:String" MinOccurs="1" MaxOccurs="1"/>
     .
     
.
     
.

 جدول زير ، انواع داده مهم حمايت شده در XSD  را نشان مي دهد .

انواع داده حمايت شده در XSD

نوع داده

توضيحات و مثال

anyuri

Uniform Resource Locator
Example : http://www.srco.ir

base64Binary

MIME STYLE base64 encoded binary data

hexBinary

Hexadecimal encoded binary data

boolean

TRUE(1) Or FALSE(0)

byte

Numbers between -128 To 127

dateTime

Date in a subset of  the ISO8601 format
Time and Timezone are optional
Example: 2003-04-15T10:40:15.000-05:00

date

Date in a subset of the ISO8601 format
Example: 2003-04-15

decimal

Positive or negative arbitrary precision decimal value
Examples: -5.34,0,5.34,5000.00

double

double precision 64-bit floating point

duration

Duration of time specified in years , months , days , hours , minutes and seconds format , as defined in the ISO8601 standards extended format PnYnMnDTnHnMnS.nY is then number of years , nM is the number of months and so on .The P is required but the other items are optional
Example:To specify duration of one year and two months you would specify : P1Y2M

float

Single precision 32-bit floating point

gDay

Day in Gregorian format
Example: --31 every 31th day,regardless of month

gMonth

Month in Gregorian format
Example: --06-- every may

gMonthDay

Month and day in Gregorian format
Example: --07-31 every july 31th

gYear

Year in Gregorian format
Example: 2000

gYearMonth

Year and month in Gregorian format
Example:2000-02

Int

Integer.Sign is optional
Range: -2147483648 to 2147483647

Integer

The standard mathematical concept of integer numbers
Range: An infinite set of negative or positive numbers

Language

Any valid XML language value as defined by RFC 1766
Example: en-US

Long

Integer
Range: -9223372036854775808 to
             9223372036854775807

Name

XML 1.0 name type

NCName

XML namespace ncname (An XML name without the prefix and colon)

negativeInteger

Range : Negative infinity to -1

nonNegativeInteger

Range : 0 to infinity

positiveInteger

Range : 1 to infinity

nonPositiveInteger

Range : Negative infinity to 0

normalizedString

String of character data. Newline,tab and carriage-return characters are converted to spaces before schema processing.

Short

Range : -32768 to 32767

String

String of character data .(characters that match CHAR from XML 1.0)

Time

Time in hh:mm:ss.sss-TimeZone format . Time zone is optional . The time zone is based on the number of hours ahead or behind coordinated universal time (as define in ISO8601)
Example : 11:45:33.20-05:00 where 05:00 means 5 hours behind universal time .

Token

string of character data . Like normalizedstring the newline,tab and carriage-return characters are converted to spaces before schema processing . In addition , adjacent space characters are collapsed to a single space and leading and trailing spaces are removed .

unsignedByte

Unsigned byte .
Range : 0 to 255

unsignedInt

Unsigned integer .
Range : 0 to 4294967295

unsignedlong

Unsigned long integer .
Range : 0 to 18446744073709551615

unsignedShort

Unsigned short integer.
Range : 0 to 65535

QName

XML namespace QName.

NOTATION

XML 1.0 NOTATION attribute type. to retain compatibility between XSD and XML DTD 1.0s. these should only be used with attributes.

NMTOKEN

Name token value. string consisting of one word in a set of letters , digits and other characters in any combination .to retain compatibility between XSD and XML DTD 1.0s. these should only be used with attributes.

NMTOKENS

List of name tokens separated by whitespace. to retain compatibility between XSD and XML DTD 1.0s. these should only be used with attributes.

ID

The ID value must be unique throughtout all elements in the XML document. This attribute is refrenced by other attributes such as idref and idrefs. to retain compatibility between XSD and XML DTD 1.0s. these should only be used with attributes.

IDREF

References the value in an ID attribute within the XML document. to retain compatibility between XSD and XML DTD 1.0s. these should only be used with attributes.

IDREFS

References multiple ID type values separated by whitespace. to retain compatibility between XSD and XML DTD 1.0s. these should only be used with attributes.

ENTITY

XML 1.0 ENTITY attribute type. to retain compatibility between XSD and XML DTD 1.0s. these should only be used with attributes.

ENTITIES

XML 1.0 ENTITIES attribute type. ENTITIES contain a set of ENTITY values.  to retain compatibility between XSD and XML DTD 1.0s. these should only be used with attributes.


ايجاد انواع داده دلخواه
همانگونه که در بخش هاي قبل اين مقاله اشاره گرديد ، ، در  XSD  اين امکان وجود خواهد داشت  که کاربر با استفاده از انواع داده استاندارد (جدول فوق) و اعمال محدوديت هاي دلخواه بر روي آنان  ، اقدام به تعريف انواع داده ساده (Simple) دلخواه خود نموده و از آنها در توصيف جاري و يا حتي ساير توصيف ها استفاده نمايد .
با توجه به اينکه نحوه تعريف انواع داده دلخواه در مقالات قبل به تفصيل بيان شده است ، در اين بخش از مقاله ، از تکرار آن خودداري نموده و صرفا" به تشريح حالات مختلف خلاصه سازي يا محدود سازي اشاره خواهد شد .

پارمترهاي محدود سازي (Facets)
خلاصه سازي و يا محدود سازي بستگي مستقيم به نوع داده پايه اي دارد که ميخواهيم محدود سازي را بر روي آن اعمال نمائيم . در خصوص داده هائي از نوع رشته‏ اي، پارمترهاي مختلف محدود سازي به شرح ذيل مي باشند :

  • enumeration
  • length
  • minlength
  • maxlength
  • pattern
  • whitespace

جدول زير نحوه استفاده از پارامتر الگو(pattern) و اعمال  کنترل هاي مختلف بمنظور تشريح  الگو را نشان مي دهد :

Regular Expression

Explanation

Example(s)

\d Digit 1,2,3, etc.
[a-z] Lower case ASCII characters a,b,c, etc.
[A-Z] Upper case ASCII characters A,B,C, etc.
* Wildcard A*Z=ABZ,AbnmZ,ADDFZ, etc.
? Single placeholder A?Z=ABZ,AbZ,ACZ, etc.
+ Inclusive of at least the specified values, but more are allowed . A+Z=AZ,ABZ,ABCZ, etc.
(Value1|Value2) Or (A|Z)+Q=AQ,ZQ,ABQ,ZBQ, etc.
[abcde] Another way to specify or , but with single character only. [abc]=a,b, or c
[^0-9] Any non-digit character A,B,C,a,b,c, etc.
{integer} The number of occurrences that there must be of the previous value . az{2} = azz
\d{3} = 123,456,789,444, etc.
(az){2} = azaz

مثال يک : در مثال زير نحوه استفاده از پارامتر الگو ، نشان داده شده است :

مثال  يک : نحوه استفاده از پارامتر الگو

<XSD:simpleType name="StudentGPA"   minOccurs="1"   maxOccurs="1">
     <XSD:restriction   base="XSD:string">
            <XSD:length  value="4" />
            <XSD:pattern value="/d{1} . /d{2}" />
     </XSD:restriction>
</XSD:simpleType>

مثال دوم : در مثال زير نحوه استفاده از پارامتر الگو ، نشان داده شده است :

مثال  دو : نحوه استفاده از پارامتر الگو

<XSD:simpleType name="StudentGPA"   minOccurs="1"   maxOccurs="1">
     <XSD:restriction   base="XSD:string">
           <XSD:enumeration Value = "2.0" />
           <XSD:enumeration Value = "2.5" />
           <XSD:enumeration Value = "3.0" />
           <XSD:enumeration Value = "3.5" />
           <XSD:enumeration Value = "4.0" />
     </XSD:restriction>
</XSD:simpleType>

نکته : در مثال دوم، ارزش هاي مختلفي  که يک سند براي عنصر StudentGPA مي تواند داشته باشد 2.0 يا 2.5 يا 3.0 يا 3.5 يا 4.0 است . اما در مثال اول طول رشته بايد چهار حرف بوده و الگوي آن نيز معادل الگوي تعريف شده در pattern باشد . حال سئوال اينجا است که در محدود سازي يک نوع داده ، جايگاه واقعي استفاده از  and و يا or چگونه است ؟. جواب اين سئوال پيچيده نيست ، در واقع ، در موارديکه از خصلت هاي enumoration و pattern استفاده مي گردد ، واقعيت or حکمفرما بوده  و  در صورت استفاده از ساير خصلت ها ، واقعيت and حکم فرما خواهد بود.

در خصوص داده هاي عددي ، پارامترهاي محدود سازي(Facets) به شرح ذيل مي باشد :

  • enumeration
  • fractionDigits
  • maxExclusive
  • minExclusive
  • maxInclusive
  • minInclusive
  • pattern
  • totalDigits
  • whiteSpace

مثال : در مثال زير نحوه استفاده از پارامترهاي محدودسازي در خصوص داده هاي عددي را نشان مي دهد :

مثال : نحوه استفاده از پارامترهاي محدودسازي در خصوص داده هاي عددي

<XSD:simpleType name="courseNumber"   minOccurs="0"   maxOccurs="10">
     <XSD:restriction   base="XSD:integer">
            <XSD:minInclusive  value="1000" />
            <XSD:maxInclusive value="
3000" />
     </XSD:restriction>
</XSD:simpleType>

در اين مثال نوع داده دلخواهي جهت توصيف عنصر شماره درس ايجاد شده است که طبق آن هر دانشجو ميتواند تا 10 درس را ثبت نام نموده و شماره هر درس نيز بين 1000 تا 3000 بايد باشد . بنابر اين در صورتيکه در يک سند XML  که از توصيف فوق استفاده نموده وعنصر course داراي مقدار 4000 و بصورت زير باشد،پارسر XSD خطائي مبني بر ايجاد مشکل در نوع داده ارائه و سند اعتبار سنجي نخواهد شد .

<course>4000</course>

در بخش هفتم اين مقاله به بررسي  مستند سازي يک توصيف يا سند XSD  خواهيم پرداخت .

برگرفته از سايت سخا روش

Add Comments
Name:
Email:
User Comments:
SecurityCode: Captcha ImageChange Image