1 / 17

XML

XML. Aynur Abdurazik. DTD. DTD ( Document Type Definition ) is a set of rules that defines a custom markup language in XML. An XML document for a particular custom markup language is not considered valid if it does not adhere to the DTD that language.

daniag
Download Presentation

XML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XML Aynur Abdurazik

  2. DTD • DTD (Document Type Definition) is a set of rules that defines a custom markup language in XML. • An XML document for a particular custom markup language is not considered valid if it does not adhere to the DTD that language. • A DTD defines the structure and contentof elements, child elements, and their attributes for a given markup language. Copyrigth Aynur Abdurazik

  3. DTD • DTD is a text-only document and is saved with a .dtd extension. • It is not an XML document itself and does not start with the standard XML declaration. Copyrigth Aynur Abdurazik

  4. DTD • DTD is a way to insure the consistency of shared XML data. DTDs are used to validate XML documents before their usage. • An XML editor or DTD processor will be needed to validate an XML document against a given DTD. Copyrigth Aynur Abdurazik

  5. DTD Syntax • Defining an element that contains text: • <!ELEMENT tag (#PCDATA) > • Tag is the name of the element you wish to define. • PCDATA (Parsed Character Data) refers to the text value of an element • XML is case sensitive – ELEMENT! and Element! are different. Copyrigth Aynur Abdurazik

  6. DTD Syntax • Defining an Empty Element: • <!ELEMENT tag EMPTY> • Tag is the name of the element you wish to define. • EMPTY indicates that the element will not contain a text value of its own. • No parenthesis around EMPTY. • EMPTY elements can have attributes that are used to store data. • Example: <!ELEMENT main_image EMPTY> Copyrigth Aynur Abdurazik

  7. DTD Syntax • Defining an Element that contains a child: • <!ELEMENT tag (child)> • Tag is the name of the element you wish to define • Child is the name of the element that will be contained in the element being defined • This element cannot contain anything other than the child element, and it must contain the child element every time • Example: <!ELEMENT students (student) > Copyrigth Aynur Abdurazik

  8. DTD Syntax • Defining an Element that contains children: • <!ELEMENT tag (child1, child2, child3)> • Example: <ELEMENT course (name, location, instructor) > • The most important thing in a sequence is comma. • (#PCDATA) cannot be used in any part of a sequence; sequences must only contain elements. • Elements contained in a sequence can have their own child elements. Copyrigth Aynur Abdurazik

  9. DTD Syntax • Defining how many occurrences: • After elements name add one of the following: • * - zero or more • + - one or more • ? – zero or one • Elements without a quantifier must appear exactly once. • There is no way to define a specific quantity of an element • <!ELEMENT course (name, location+, instructor+)> Copyrigth Aynur Abdurazik

  10. DTD Syntax • Defining Choices: • <!ELEMENT tag (child1 | child2 | child3) > • Defining an element that contains anything: • <!ELEMENT tag ANY> • ANY allows the element to contain any combination of elements and parsed character data. • If the element contains child element, children should be defined in the DTD. Copyrigth Aynur Abdurazik

  11. DTD Attributes • Attributes provide additional data about an element. • Elements are better used for information to be displayed • Attributes are better used for information about information. • Attributes are often used with empty elements. Copyrigth Aynur Abdurazik

  12. Defining Attributes • <!ELEMENT tag att_name CDATA #IMPLIED|#REQUIRED > • Att_name is the name of an attribute • CDATA (character data) will not be parsed by the processor. • #IMPLIED indicates the attribute may be omitted • #REQUIRED indicates the attribute may not be omitted and must contain a value • Definitions are case sensitive Copyrigth Aynur Abdurazik

  13. XML Entities • Entities are like autotext entries or shortcuts • Define entity name and the text it represents, • entity reference is expanded into the defined text • Two main types of entities: • General entities: can be expanded only in XML doc • Further divided into internal and external, parsed or unparsed • Parameter entities: can be expanded only in DTDs • Can be divided into internal and external, but are always parsed. Copyrigth Aynur Abdurazik

  14. Creating an External General Entity • Larger entities or entities could be reused in multiple DTDs can be saved in a separate, external text file with .ent extension. • <!ENTITY ent_name SYSTEM “entity.uri”> • “entity.uri” specifies the location of the entity file. Copyrigth Aynur Abdurazik

  15. XML Schema • Associating and XML Schema with an XML document: <?xml version=“1.0”?> <root_namexmlns:xsi=http://www.w3.org/2001/XMLSchema-instancexsi:noNamespaceSchemaLocation=“xsd.uri”> … </root_name> Copyrigth Aynur Abdurazik

  16. Deriving Custom Simple Types <xs:element name=“label”> • “label” is the name of XML element <xs:simpleType name=“custom_type_name”> <xs:restriction base=“foundation”> - “foundation” is any of the built-in simple types Specify restrictions </xs:restriction> </xs:simpleType> </xs:element> Copyrigth Aynur Abdurazik

  17. Named Custom Type <xs:simpleType name=“custom_type_name”> <xs:restriction base=“foundation”> - “foundation” is any of the built-in simple types Specify restrictions </xs:restriction> </xs:simpleType> <xs:element name=“label” type=“custom_type_name”> Copyrigth Aynur Abdurazik

More Related