讲义参考分析_第1页
讲义参考分析_第2页
讲义参考分析_第3页
讲义参考分析_第4页
讲义参考分析_第5页
已阅读5页,还剩43页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、2022-4-22BUPTSSEXML & Web ServiceBy Professor Guoshi Wu By Professor Guoshi Wu Email: Email: Work Phone: Work Phone: 2022-4-22BUPTSSELecture 3XML DTDBy Professor Guoshi Wu By Professor Guoshi Wu Email: Email: Work Phone: Work Phone: 2022-4-22BUPTSSEDTD(Document Type Definition) DTD Purpose?The p

2、urpose of a Document Type Definition is to define the legal building blocks of an XML document. It defines the document structure with a list of legal elements.Why use a DTD? XML provides an application independent way of sharing data. With a DTD, independent groups of people can agree to use a comm

3、on DTD for interchanging data. Your application can use a standard DTD to verify that data that you receive from the outside world is valid. You can also use a DTD to verify your own data. 2022-4-22BUPTSSEDTD(Document Type Definition) DTD is set of rules that you use to guide production of XML docum

4、entsSharing VocabulariesEasily integrate with other companies and XML developersMany individuals and industries have developed DTDs that are de facto standards 2022-4-22BUPTSSEInternal DOCTYPE declaration If the DTD is included in your XML source file, it should be wrapped in a DOCTYPE definition wi

5、th the following syntax:Example !DOCTYPE note Tove Jani Reminder Dont forget me this weekend 2022-4-22BUPTSSEExternal DOCTYPE declaration If the DTD is external to your XML source file, it should be wrapped in a DOCTYPE definition with the following syntax:Example Tove Jani Reminder Dont forget me t

6、his weekend 2022-4-22BUPTSSESystem IdentifiersA system identifier allows you to specify the physical location of a file on your system. It is comprised of two parts: the keyword SYSTEM followed by a URI reference to a document with a physical location.Legal System Identifiers 2022-4-22BUPTSSEPublic

7、Identifiers Public identifiers provide a second mechanism to locate DTD resources. According to the XML specification, public identifiers can follow any format, however, there is a commonly used format called Formal Public Identifiers, or FPIs : The delimiter / separates each section. Generally, the

8、re are five sections of a FPI:Registration IndicatorOwnerClass Name and DescriptionLanguageDisplay Version -/Owner/Class Description/Language/Version2022-4-22BUPTSSEThe building blocks of XML documents(1)Seen from a DTD point of view, all XML documents (and HTML documents) are made up by the followi

9、ng simple building blocks:Elements Attributes Entities PCDATA CDATA 2022-4-22BUPTSSEThe building blocks of XML documents(2)Elements Elements are the main building blocks of both XML and HTML documents. Tags Tags are used to markup elements. Attributes Attributes provide extra information about eleme

10、nts.Entities Entities are variables used to define common text. Entity references are references to entities.PCDATA PCDATA means parsed character data.CDATA CDATA also means character data.2022-4-22BUPTSSEElement Declarations(1) The ELEMENT declaration The element name The element content model Empt

11、y Element Mixed Any2022-4-22BUPTSSEElement Declarations(2)The element content model1. Empty Content2. It functions in the same way as a tag within HTML It is important to remember that this will require that the element be empty within the XML document. You should not declare elements that may conta

12、in content using the EMPTY keyword. 2022-4-22BUPTSSEElement Declarations(3)The element content model3. Element Content 2022-4-22BUPTSSEElement Declarations(4)The element content modelElement ContentThere are two fundamental ways of specifying that an element will contain more than one child:Sequence

13、sChoicesCombining Sequences and Choices 1) Have to have exactly four children with DTD defined names2) Have to have exactly orders with DTD defined names 2022-4-22BUPTSSEElement Declarations(5)The element content modelMixed ContentAny element with text in its content is a mixed content model element

14、. There is only one way to declare a mixed content model within DTDs. In the mixed content model, we must use the choice mechanism when adding elements. This means that each element within our content model must be separated by the vertical bar (|) character:Without question, Weird Al is the greates

15、t singer of all time! They must use the choice mechanism to separate elements.The #PCDATA keyword must appear first in the list of elements.There must be no inner content models.The * cardinality indicator must appear at the end of the model.2022-4-22BUPTSSEElement Declarations(6)The element content

16、 model Any Content we can declare our element utilizing the ANY keyword: In the above, ANY keyword indicates that any elements declared within the DTD may be used within the content of the element, and that they may be used in any order any number of time 2022-4-22BUPTSSEElement Declarations(7)cardi

17、nalityAn elements cardinality defines how many times it will appear within a content modelIndicatorIndicatorDescriptionDescriptionnoneIndicates that the element must appear once and only once?Indicates that the element may appear either once or not at all+Indicates that the element may appear one or

18、 more times*Indicates that the element may appear zero or more times2022-4-22BUPTSSEElement Declarations(8)cardinalityExamples Like A Virgin Madonna Like A Virgin Madonna Like A Virgin Madonna2022-4-22BUPTSSEElement Declaration Example(1)If an element name in DTD is followed by the star *, this elem

19、ent can occur zero, once or several times.DTDThe root element XXX can contain zero or more elements AAA followed by precisely one element BBB. Element BBB must be always present .A valid XML DocumentAnother valid document. The element AAA is not mandatory 2022-4-22BUPTSSEElement Declaration Example(

20、2)If an element name in DTD is followed by the plus +, this element can occur once or several times.DTDThe root element XXX must contain one or several elements AAA followed by precisely one element BBB. Element BBB must be always present.A valid XML DocumentSeveral AAA elements can occur inside the

21、 document 2022-4-22BUPTSSEElement Declaration Example(3) If an element name in DTD is followed by the question mark ?, this element can occur zero or one times DTDThe root element XXX can contain one element AAA followed by precisely one element BBB. Element BBB must be always present.A valid XML Do

22、cumentElement AAA is not mandatory 2022-4-22BUPTSSEElement Declaration Example(4)This example uses a combination of + * ?DTDThe root element XXX can contain one element AAA followed by one or more elements BBB. Element AAA can contain one element CCC and several elements DDD. Element BBB must contai

23、n precisely one element CCC and one element DDD:A valid XML Document2022-4-22BUPTSSEElement Declaration Example(5)This example uses a combination of + * ? Elements in AAA are not mandatory: Element AAA can be omitted: 2022-4-22BUPTSSEElement Declaration Example(6)With character | you can select one

24、from several elementsDTDA valid document: 2022-4-22BUPTSSEElement Declaration Example(7) Another valid document: 2022-4-22BUPTSSEText can be interspersed with elements.DTDA valid document: Element Declaration Example(8)2022-4-22BUPTSSEAttribute Declarations The ATTLIST keywordThe associated elements

25、 nameThe list of declared attributesThe attribute nameThe attribute typeThe attribute value declaration2022-4-22BUPTSSEAttribute Name To declare an attribute name you simply type the name exactly as it will appear in the XML document, including any namespace prefix.we must also make sure that we don

26、t have duplicate names within our attribute list. Remember duplicate attribute names are not allowed within a single element. 2022-4-22BUPTSSEAttribute TypeTypeTypeDescriptionDescriptionCDATAThe value is character dataIDThe value is a unique id IDREFThe value is the id of another elementIDREFSThe va

27、lue is a list of other idsENTITYThe value is an entity ENTITIESThe value is a list of entitiesNMTOKENIndicates that the attribute value is a XML name tokenNMTOKENSThe value is a list of valid XML namesEnumerated ListThe value must be one from an enumerated list2022-4-22BUPTSSEAttribute default-value

28、Value Explanation Value The default value of the attribute#REQUIREDThe attribute value must be included in the element#IMPLIEDThe attribute does not have to be included#FIXED valueThe attribute value is fixed2022-4-22BUPTSSEAttribute Declaration Example(1)Attributes are used to associate name-value

29、pairs with elements. DTD:An attribute of CDATA type can contain any character if it conforms to well formedness constraints. The required attribute must be always present, the implied attribute is optional: 2022-4-22BUPTSSEAttribute Declaration Example(2)Valid documents: CDATA attribute can contain

30、any character conforming to well-formedness:The order of attributes is not important: The bbb attribute can be omitted as it is implied: Text2022-4-22BUPTSSEAttribute Declaration Example(3)An attribute of CDATA type can contain any character if it conforms to well formedness constraints. NMTOKEN typ

31、e can contain only letters, digits and point . , hyphen - , underline _ and colon : . NMTOKENS can contain the same characters as NMTOKEN plus whitespaces. White space consists of one or more space characters, carriage returns, line feeds, or tabs. DTD:The attributes bbb and ccc must be always prese

32、nt, the attribute aaa is optional 2022-4-22BUPTSSEAttribute Declaration Example(4)An attribute of CDATA type can contain any character if it conforms to well formedness constraints. NMTOKEN type can contain only letters, digits and point . , hyphen - , underline _ and colon : . NMTOKENS can contain

33、the same characters as NMTOKEN plus whitespaces. White space consists of one or more space characters, carriage returns, line feeds, or tabs. Valid documents: All required attributes are present and their values are of the correct type 2022-4-22BUPTSSEAttribute Declaration Example(5) The value of an

34、 attribute of ID type can contain only characters permitted for NMTOKEN and must start with a letter. No element type may have more than one ID attribute specified. The value of an ID attribute must be unique between all values of all ID attributes.DTD:The attributes id, code and X uniquely determin

35、e their element: 2022-4-22BUPTSSEAttribute Declaration Example(6)The value of an attribute of ID type can contain only characters permitted for NMTOKEN and must start with a letter. No element type may have more than one ID attribute specified. The value of an ID attribute must be unique between all

36、 values of all ID attributes.All ID values are unique : 2022-4-22BUPTSSEAttribute Declaration Example(7)The value of IDREF attribute must match the value of some ID attribute in the document. The value of IDREFS attribute can contain several references to elements with ID attribute separated with wh

37、itespaces.The attributes id and mark uniquely determine their element. The attributes ref refer to these elements: :Tutorial.dtd2022-4-22BUPTSSEAttribute Declaration Example(7)All ID values are unique and all IDREF and IDREFS point to elements with relevant IDs: A valid XML Document for Tutorial.dtd

38、2022-4-22BUPTSSEAttribute Declaration Example(8) Invalid XML Documents for Tutorial.dtd2022-4-22BUPTSSEAttribute Declaration Example(9)If an attribute is implied, a default value can be provided for the case when the attribute is not used.DTD:Both attributes are implied. Their default value is given

39、.The values of true are yes, no and yes. The values of month are 8, 2 and 1. 2022-4-22BUPTSSEAttribute Declaration Example(10)An element can be defined EMPTY. In such a case it can contain only attributes but no text.DTD:The AAA elements can contain only attributes but no text: Both these forms are

40、allowed. In the second case the ending tag must immediately follow the starting one: 2022-4-22BUPTSSE Entities (1)Built-in EntitiesCharacter EntitiesGeneral EntitiesParameter Entities5 > 4 © 2001 Wrox Press 2022-4-22BUPTSSEEntities(2)Character Entities: Much like the five built-in en

41、tities, are not declared within the DTD. Instead, they can be used in the document within element and attribute content, without any declaration.References to Character EntitiesThe Most Popular Character Entities © Copy Right 2022-4-22BUPTSSEEntities (3)General Entities : General entities m

42、ust be declared within the DTD before they can be used within the XML document. Most commonly, XML developers use general entities to create reusable sections of replacement text. (Much more like Macro)Internal entity declarationLegal EntitiesIllegal Entities !ENTITY parody parody !ENTITY johndoe John Fitzgerald Doe !ENTITY startSong

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论