Sunday 8 July 2012

EMBEDDED IMAGES


EMBEDDED IMAGES






To embed non-XML data (such as an image) into your XML document, you need to treat it as 


an external unparsed entity. To declare an external unparsed entity, you use the <!ENTITY> 


declaration along with the NDATA keyword.









Syntax

<!ENTITY name SYSTEM value NDATA TYPE>


You can also use public external unparsed entities by using the PUBLIC keyword along with a Formal Public Identifier (FPI):

<!ENTITY name PUBLIC FPI value NDATA TYPE>

Example


Here's an example of a private external unparsed entity. Here, we declare a new notation named "JPG" for the "image/jpeg" MIME type. Then we declare an external unparsed entity called "mt_cook_1" that refers to an image file called "mt_cook1_jpg". We then create a new attribute of type ENTITY - this means that we can now use this attribute in our XML document to refer to the unparsed external entity.

<!NOTATION JPG SYSTEM "image/jpeg">
<!ENTITY mt_cook_1 SYSTEM "mt_cook1.jpg" NDATA JPG>
<!ATTLIST mountain photo ENTITY #IMPLIED>

After declaring the external unparsed entity in our DTD (and creating an attribute of type ENTITY), we can now embed it in our XML document:

<mountains> <mountain photo="mt_cook_1">  
<name>Mount Cook</name> </mountain>  
<mountain> <name>Cradle Mountain</name> </mountain>
</mountains>

Embedding Multiple Images


If you need to embed multiple external unparsed entities via a single attribute, you simply give your attribute a type of ENTITIES (plural). This allows you to assign multiple images separated by a space.
Here's an example:
<!NOTATION JPG SYSTEM "image/jpeg">
<!ENTITY mt_cook_1 SYSTEM "mt_cook1.jpg" NDATA JPG>
<!ENTITY mt_cook_2 SYSTEM "mt_cook2.jpg" NDATA JPG>
<!ATTLIST mountain photo ENTITIES #IMPLIED>


Now that we've changed the "photo" attribute to type ENTITIES, we can assign multiple images to it in our XML document:

<mountains> <mountain photo="mt_cook_1 mt_cook_2"> 
<name>Mount Cook</name> </mountain> 
<mountain> <name>Cradle Mountain</name> 
</mountain></mountains>

FPI


FPI


When declaring a DTD available for public use, you need to use the PUBLIC keyword within 

your DOCTYPE declaration. When you use the PUBLIC keyword, you also need to use an FPI 

(which stands for Formal Public Identifier).



FPI Syntax

An FPI is made up of 4 fields, each separated by double forward slashes (//):

field 1//field 2//field 3//field 4
FPI Example

Here's a real life example of an FPI. In this case, the DTD was created by the W3C for XHTML:

-//W3C//DTD XHTML 1.0 Transitional//EN
FPI Fields

An FPI must contain the following fields:

Field
Example
Description
Separator
//
This is used to separate the different fields of the FPI.
First field
-
Indicates whether the DTD is connected to a formal 
standard or not. If the DTD hasn't been approved (for 
example, you've defined the DTD yourself), use a 
hypen (-). If the DTD has been approved by a 
nonstandards body, use a plus sign "+". If the DTD 
has been approved by a formal standards body this 
field should be a reference to the standard itself.
Second 
field
W3C
Holds the name of the group (or person) responsible 
for the DTD. The above example is maintained by the 
W3C, so "W3C" appears in the second field.
Third field
DTD XHTML 1.0 Transitional
Indicates the type of document that is being
 described. This usually contains some form of unique 
identifier (such as a version number).
Fourth 
field
EN

Specifies the language that the DTD uses. This is 
achieved by using the two letter identifier for the 
language (i.e. for english, use "EN").



FPI DOCTYPE Syntax

When using a public DTD, place the FPI between the PUBLIC keyword and the URI/URL.

<!DOCTYPE rootname PUBLIC FPI URL>
FPI DOCTYPE Example

You can see an example of an FPI in the following DOCTYPE declaration (the FPI is in bold):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Friday 6 July 2012

MUST READ


TV Schedule DTD

<!DOCTYPE TVSCHEDULE [

<!ELEMENT TVSCHEDULE (CHANNEL+)>
<!ELEMENT CHANNEL (BANNER,DAY+)>
<!ELEMENT BANNER (#PCDATA)>
<!ELEMENT DAY (DATE,(HOLIDAY|PROGRAMSLOT+)+)>
<!ELEMENT HOLIDAY (#PCDATA)>
<!ELEMENT DATE (#PCDATA)>
<!ELEMENT PROGRAMSLOT (TIME,TITLE,DESCRIPTION?)>
<!ELEMENT TIME (#PCDATA)>
<!ELEMENT TITLE (#PCDATA)>
<!ELEMENT DESCRIPTION (#PCDATA)>

<!ATTLIST TVSCHEDULE NAME CDATA #REQUIRED>
<!ATTLIST CHANNEL CHAN CDATA #REQUIRED>
<!ATTLIST PROGRAMSLOT VTR CDATA #IMPLIED>
<!ATTLIST TITLE RATING CDATA #IMPLIED>
<!ATTLIST TITLE LANGUAGE CDATA #IMPLIED>
]>


Newspaper Article DTD

<!DOCTYPE NEWSPAPER [

<!ELEMENT NEWSPAPER (ARTICLE+)>
<!ELEMENT ARTICLE (HEADLINE,BYLINE,LEAD,BODY,NOTES)>
<!ELEMENT HEADLINE (#PCDATA)>
<!ELEMENT BYLINE (#PCDATA)>
<!ELEMENT LEAD (#PCDATA)>
<!ELEMENT BODY (#PCDATA)>
<!ELEMENT NOTES (#PCDATA)>

<!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED>
<!ATTLIST ARTICLE EDITOR CDATA #IMPLIED>
<!ATTLIST ARTICLE DATE CDATA #IMPLIED>
<!ATTLIST ARTICLE EDITION CDATA #IMPLIED>

<!ENTITY NEWSPAPER "Vervet Logic Times">
<!ENTITY PUBLISHER "Vervet Logic Press">
<!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press">

]>


Product Catalog DTD

<!DOCTYPE CATALOG [

<!ENTITY AUTHOR "John Doe">
<!ENTITY COMPANY "JD Power Tools, Inc.">
<!ENTITY EMAIL "jd@jd-tools.com">

<!ELEMENT CATALOG (PRODUCT+)>

<!ELEMENT PRODUCT
(SPECIFICATIONS+,OPTIONS?,PRICE+,NOTES?)>
<!ATTLIST PRODUCT
NAME CDATA #IMPLIED
CATEGORY (HandTool|Table|Shop-Professional) "HandTool"
PARTNUM CDATA #IMPLIED
PLANT (Pittsburgh|Milwaukee|Chicago) "Chicago"
INVENTORY (InStock|Backordered|Discontinued) "InStock">

<!ELEMENT SPECIFICATIONS (#PCDATA)>
<!ATTLIST SPECIFICATIONS
WEIGHT CDATA #IMPLIED
POWER CDATA #IMPLIED>

<!ELEMENT OPTIONS (#PCDATA)>
<!ATTLIST OPTIONS
FINISH (Metal|Polished|Matte) "Matte"
ADAPTER (Included|Optional|NotApplicable) "Included"
CASE (HardShell|Soft|NotApplicable) "HardShell">

<!ELEMENT PRICE (#PCDATA)>
<!ATTLIST PRICE
MSRP CDATA #IMPLIED
WHOLESALE CDATA #IMPLIED
STREET CDATA #IMPLIED
SHIPPING CDATA #IMPLIED>

<!ELEMENT NOTES (#PCDATA)>

]>

DTD Validation


DTD Validation

With Internet Explorer you can validate your XML against a DTD.

Validating With the XML Parser

If you try to open an XML document, the XML Parser might generate an error. By accessing the parseError object, you can retrieve the error code, the error text, or even the line that caused the error.

hint: The load( ) method is used for files, while the loadXML( ) method is used for strings.

Example
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.validateOnParse="true";
xmlDoc.load("note_dtd_error.xml");

document.write("<br />Error Code: ");
document.write(xmlDoc.parseError.errorCode);
document.write("<br />Error Reason: ");
document.write(xmlDoc.parseError.reason);
document.write("<br />Error Line: ");
document.write(xmlDoc.parseError.line);


Turn Validation Off


Turn Validation Off

Validation can be turned off by setting the XML parser's validateOnParse="false".

Example

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.validateOnParse="false";
xmlDoc.load("note_dtd_error.xml");

document.write("<br />Error Code: ");
document.write(xmlDoc.parseError.errorCode);
document.write("<br />Error Reason: ");
document.write(xmlDoc.parseError.reason);
document.write("<br />Error Line: ");
document.write(xmlDoc.parseError.line);

An Internal Entity Declaration


An Internal Entity Declaration

Syntax

<!ENTITY entity-name "entity-value">

Example


DTD Example:

<!ENTITY writer "Donald Duck.">
<!ENTITY copyright "Copyright W3Schools.">

XML example:

<author>&writer;&copyright;</author>

HINT: An entity has three parts: an ampersand (&), an entity name, and a semicolon (;).


An External Entity Declaration


An External Entity Declaration

Syntax

<!ENTITY entity-name SYSTEM "URI/URL">

Example

DTD Example:

<!ENTITY writer SYSTEM "http://www.yahoo.com/entities.dtd">
<!ENTITY copyright SYSTEM "http://www.yahoo.com/entities.dtd">

XML example:

<author>&writer;&copyright;</author>