Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

XML DTDs : Page 7

Valid XML documents follow a set of rules defined in a associated DTD. This Document Type Definition defines elements, attributes, and relationships between elements.


advertisement

Entities
An entity is a short cut to a set of information.

When you use an entity, it "expands" to its full meaning, but you need only type the shorter entity name during data entry. You might think of an entity as being a bit like a macro -- it is a set of information that can be used by calling one name.

XML defines two types of entities.



The general entity is one that you define in a DTD and use in a document. General entities are easy to spot. They are defined with the entity declaration, <!ENTITY, and when they are used they begin with the ampersand and end with the semicolon, like this:

&entity-name;

The parameter entity is one that you define and use within a DTD. The content of a parameter entities may be either included in the DTD or stored in an external file. In addition, parameter entities must be parsed; they cannot be unparsed. That is, they must contain textual data that is processed rather than a GIF or other non-textual data type.

It too is defined with a entity declaration, but it is called with a percent sign, like this:

%info;

Defining a General Entity
To define an entity:

  1. Start the entity definition, with a less than sign, an exclamation mark, and the phrase ENTITY, all in caps:

    <!ENTITY

  2. Type the name of the entity. Type it using the capitalization that you will use when calling it later on.

    <!ENTITY copyright

  3. If you are defining the entity locally, type the value of the entity, surrounded by quotes, and then close the entity definition with a greater than sign.

    <!ENTITY copyright "Copyright 2000, As The World Spins Corp. All rights reserved. Please do not copy or use without authorization. For authorization contact legal@worldspins.com.">

  4. If you are defining an entity in an external, ascii text file, put in a pointer to the external file, then close the entity definition with a greater than sign.

    <!ENTITY copyright SYSTEM "http://www.worldspins.com/legal/copyright.xml">

Using a General Entity
You won't be using a general entity in a DTD. You will only be defining it here. You will be using it in an XML file, where it is called by tying an ampersand, the entity name, and a semi-colon, &entity-name;

Defining a Parameter Entity
To declare a parameter entity:

  1. Type the entity declaration:

    <!ENTITY

  2. Type a space, followed by a percent sign. It is important to remember the space!

    <ENTITY %

  3. Type another space, followed by the name of the entity:

    <!ENTITY % list

  4. Type the value of the entity, surrounded by quotation marks:

    <!ENTITY % list "name CDATA #REQUIRED gender (m | f) "f" color (red | fawn | merle | black)"

  5. End the declaration with an end tag symbol.

    <!ENTITY % info "name CDATA #REQUIRED gender (m | f) #REQUIRED color (red | fawn | merle | black |other) #REQUIRED"

One thing to notice about entities in a DTD is that when they are defined there is a space between the percent sign and the entity name--but when the entity is used there is no space between the percent sign and the entity name.

Using a Parameter Entity
It is quite simple to use a parameter entity. Simply enter the entity name, preceded by a percent sign and followed by a semi-colon, like this:

<HOUND (NAME)>
<!ATTLIST HOUND %info;>

<WORKING (NAME)>
<!ATTLIST WORKING %info;>

<COMPANION (NAME)>
<!ATTLIST COMPANION %info;>

When the DTD is processed, the entity will be expanded. In this example, %info; will be replaced with a set of attribute data, which was defined in the info entity declaration.

Again, remember that when a parameter entity is defined, there is a space between the percent sign and the entity name--but when the entity is used there is no space between the percent sign and the entity name.





Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date