Tải bản đầy đủ (.pptx) (46 trang)

Báo Cáo Đặc tả hình thức

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (749.43 KB, 46 trang )

LOGO
Đặc tả hình thức
Đặc tả hình thức
GVHD:Thầy Nguyễn Trần Thi Văn
Vũ Minh Hải 07110037
Lâm Chí Hiền 07110041
Nguyễn Công Hiếu 07110045
Chiếng Mành Sâm 07110100
Thành Viên:
LOGO
Entities and External DTD Subsets
Entities and External DTD Subsets
What is an entity?
1
Internal general entities
2
External general entities
3
Internal parameter entities
4
External parameter entities
5
LOGO
How to build a document from pieces
6
Entities and DTDs in well-formed documents
7
LOGO

Document pieces, or “storage units”


This is often a file (an external entity) or a character string delimited by quotes and included as
part of the entity’s declaration (an internal entity).

Simplify writing of documents and DTD grammars

Modularize documents and DTD grammars

Most entities have names by which you can refer to them
What is an entity?
1
LOGO

Type of Entities
Entities
General Entities
Parameter Entities
Internal General Entities External General Entities
Internal Parameter
Entities
External Parameter
Entities
What is an entity? (cont)
1
LOGO

Type of Entities

Parsed and Unparsed Entities?
Entities
Entities

Parsed Entities
Parsed Entities
Unparsed Entities
Unparsed Entities
Internal Entities
Internal Entities
External Entities
External Entities
Internal Entities
Internal Entities
What is an entity? (cont)
1
LOGO

Parsed Entities: A parsed entity's contain well-formed XML text

Unparsed entities: Binary data, non-XML text (Aren’t well supported)
What is an entity? (cont)
1
LOGO
a. Defining an Internal General Entity Reference

Internal general entity references are defined in the DTD with the <!ENTITY> tag,
which has the following format:

<!ENTITY name “replacement text”>
Internal general entities (cont)
2
LOGO
Commonly used text or text that’s hard to type?

Commonly used text or text that’s hard to type?
Need replacement text
Need replacement text
Solution: An <!ENTITY> tag in the DTD
Solution: An <!ENTITY> tag in the DTD
In C we have:
#define PI 3,14159
Reference
Internal general entities
2
LOGO

General entity references begin with an ampersand (&) and end with a semicolon
(;)

For instance, &lt; is a general entity reference for the less than sign (<)

Entity names consist of any set of alphanumeric characters and the underscore.
Whitespace and other punctuation characters are prohibited.
Internal general entities (cont)
2
LOGO
11
<!ENTITY WWW “World Wide Web”>
<p>We all use the &WWW;.</p>
Internal Entity Declaration
Entity Reference
<p>We all use the World Wide Web.</p>
Logically equivalent to actually appearing
DTD

XML
Internal general entities (cont)
2
LOGO

<!ENTITY EMAIL “”>

<!ENTITY EMAIL “”>


Change?
Internal general entities (cont)
2
LOGO
b. Using General Entity References in the DTD

<!ENTITY VMH “Vu Minh Hai”>

<!ENTITY COPY99 “Copyright 1999 &VMH;”>
.
This example is in fact valid VMH entity appears as part of the COPY99
Internal general entities (cont)
2
LOGO
<!ENTITY SIGNATURE
“<SIGNATURE>
<COPYRIGHT>1999 Elliotte Rusty Harold</COPYRIGHT>
<EMAIL></EMAIL>
<LAST_MODIFIED>March 10, 1999</LAST_MODIFIED>
</SIGNATURE>”

>
Internal general entities (cont)
2
LOGO

Restrictions

The first restriction: Cannot use a circular reference like this one:

<!ENTITY VMH “&COPY99 Vu Minh Hai”>

<!ENTITY COPY99 “Copyright 1999 &VMH;”>

The second restriction: General entity references may not insert text that is only part
of the DTD

<!ENTITY PCD “(#PCDATA)”>

<!ELEMENT ANIMAL &PCD;>

<!ELEMENT FOOD &PCD;>
Internal general entities (cont)
2
LOGO

The only restriction on general entity values is that they may not contain the
three characters %, &, and “ directly

The lack of restrictions means that an entity may contain tags and span multiple
lines

Internal general entities (cont)
2
LOGO
c. Predefined General Entity References

“For interoperability, valid XML document should declare these entities, like any
others, before using them.” (declare as internal entities, see the example below)

<!ENTITY lt “&#38;#60;”>

<!ENTITY gt “&#62;”>

<!ENTITY amp “&#38;#38;”>

<!ENTITY apos “&#39;”>

<!ENTITY quot “&#34;”>
Internal general entities (cont)
2
LOGO
&lt; Produces the left angle bracket <
&gt; Produces the right angle bracket >
&amp; Produces the ampersand &
&apos; Produces a single quote character ‘
&quot; Produces a double quote character “
There are five predefined ( = no need to declare) XML entities, most of which should be well known to HTML
coders:
Internal general entities (cont)
2
LOGO


External entities are data outside the main file containing the root
element/document entity.

External entity references let you embed these external entities in your document
and build XML documents from multiple independent files.
External general entities
3
LOGO

Declaration:

You declare the external reference with the following syntax:

<!ENTITY name SYSTEM “URI”>

Example:
<?xml version=”1.0”?>
<SIGNATURE>
<COPYRIGHT>1999 Elliotte Rusty Harold</COPYRIGHT>
<EMAIL></EMAIL>
</SIGNATURE>
/> />External general entities (cont)
3
LOGO

Adding the following declaration to the DTD:

<!ENTITY SIG SYSTEM “ /> You can also use a relative URL. For example,


<!ENTITY SIG SYSTEM “/xml/signature.xml”>
 If the file to be included is in the same directory as the file doing the including:

<!ENTITY SIG SYSTEM “signature.xml”>
External general entities (cont)
3
LOGO
22
<!ENTITY chap1 SYSTEM "http:// chap1.xml">
<mylife> &chap1; &chap2;</mylife>
External Entity Declaration
Entity Reference
<mylife> <teen>yada yada</teen>
<adult> blah blah</adult>
</mylife>
Logically equivalent to inlining file contents
URL
DTD
XML
External general entities (cont)
3
LOGO

Parameter entity references begin with a percent sign (%) rather than an ampersand (&).

Parameter entity references can only appear in the DTD, not the document content.

The syntax:

<!ENTITY % name “replacement text”>


<!ENTITY % ERH “Elliotte Rusty Harold”>

<!ENTITY COPY99 “Copyright 1999 %ERH;”>
 <!ENTITY % PCD “(#PCDATA)”>
 <!ELEMENT ANIMAL %PCD;>
 <!ELEMENT FOOD %PCD;>
Internal parameter entities
4
LOGO

The real value of parameter entity references appears in sharing common lists of children and attributes between
elements

Assume we have 3 elements as below:

<!ELEMENT PARAGRAPH
(PERSON | DEGREE | MODEL | PRODUCT | ANIMAL | INGREDIENT)*>

<!ELEMENT CELL
(PERSON | DEGREE | MODEL | PRODUCT | ANIMAL | INGREDIENT)*>

<!ELEMENT HEADING
(PERSON | DEGREE | MODEL | PRODUCT | ANIMAL | INGREDIENT)*>
How a bout 30 or
300 elements ?
How a bout 30 or
300 elements ?
Internal parameter entities (cont)
4

LOGO

Solution:

<!ENTITY % inlines
“(PERSON | DEGREE | MODEL | PRODUCT | ANIMAL | INGREDIENT)*”>
<!ELEMENT PARAGRAPH %inlines;>
<!ELEMENT CELL %inlines;>
<!ELEMENT HEADING %inlines;>
To add a new element, you only have to change a
single parameter entity
declaration, rather than three, 30, or 300 element
declarations.
To add a new element, you only have to change a
single parameter entity
declaration, rather than three, 30, or 300 element
declarations.
Internal parameter entities (cont)
4

×