XML Tutorial

DTD Tutorial

XPath Tutorial



DTD Attribute Token Types


DTD attribute token types allow only certain value in a specific structure. following are some token type.

DTD Attribute Token Types

CDATA

CDATA specifies the character string type data.

Syntax :

<ATTLIST element_name attr_name CDATA attr_declaration>

Example :

<?xml version="1.0" standalone="yes"?>
<!DOCTYPE empinfo [
	<!ELEMENT empinfo (employee)>
	<!ELEMENT employee (designation)>
	<!ELEMENT designation (#PCDATA)>
	<!ATTLIST designation discipline CDATA "web_developer">
]>

<empinfo>
	<employee id="1">
		<designation>Senior Engineer</designation>
	</employee>
	<employee id="2">
		<designation discipline="DBA">Senior Engineer</designation>
	</employee>
</empinfo>

Run it...   »

Example Result:


ID

ID specifies the unique identifier. No element can have same ID in XML document.

Syntax :

<ATTLIST element_name attr_name ID attr_declaration>

Example :

<?xml version="1.0" standalone="yes"?>
<!DOCTYPE empinfo [
	<!ELEMENT empinfo (employee)>
	<!ELEMENT employee (designation)>
	<!ATTLIST employee id CDATA #REQUIRED>
	<!ELEMENT designation (#PCDATA)>
	<!ATTLIST designation discipline CDATA "web_developer">
]>

<empinfo>
	<employee id="1">
		<designation>Senior Engineer</designation>
	</employee>
	<employee id="2">
		<designation discipline="DBA">Senior Engineer</designation>
	</employee>
</empinfo>

Run it...   »

Example Result:


IDREF

IDREF specifies to a another elements id attribute value.

Syntax :

<ATTLIST element_name attr_name IDREF attr_declaration>

Example :

<?xml version="1.0" standalone="yes"?>
<!DOCTYPE empinfo [
	<!ELEMENT empinfo (employee)>
	<!ELEMENT employee (designation)>
	<!ATTLIST employee id ID #REQUIRED>
	<!ATTLIST employee user_id IDREF #REQUIRED>
	<!ELEMENT designation (#PCDATA)>
]>

<empinfo>
	<employee id="1" user_id="2">
		<designation>Senior Engineer</designation>
	</employee>
	<employee id="2" user_id="3">
		<designation>Senior Engineer</designation>
	</employee>
	<employee id="3" user_id="1">
		<designation>Senior Engineer</designation>
	</employee>
</empinfo>

Run it...   »

Example Result:


IDREFS

IDREFS specifies one or more ID reference value separated by blank spaces.

Syntax :

<ATTLIST element_name attr_name IDREFS attr_declaration>

Example :

<?xml version="1.0" standalone="yes"?>
<!DOCTYPE empinfo [
	<!ELEMENT empinfo (employee)>
	<!ELEMENT employee (designation)>
	<!ATTLIST employee id ID #REQUIRED>
	<!ATTLIST employee user_id IDREFS #IMPLIED>
	<!ELEMENT designation (#PCDATA)>
]>

<empinfo>
	<employee id="1" user_id="2 3">
		<designation>Senior Engineer</designation>
	</employee>
	<employee id="2">
		<designation>Senior Engineer</designation>
	</employee>
	<employee id="3">
		<designation>Senior Engineer</designation>
	</employee>
</empinfo>

Run it...   »

Example Result:


ENTITY

ENTITY refer to a name of the entity. Allow only specified entity.

Syntax :

<ATTLIST element_name attr_name IDREFS attr_declaration>
<ENTITY entity_name entity_definition>
...

Example :

<?xml version="1.0" standalone="yes"?>
<!DOCTYPE empinfo [
	<!ELEMENT empinfo (employee)>
	<!ELEMENT employee (designation)>

	<!ELEMENT designation (#PCDATA)>
	<!ATTLIST designation discipline ENTITY #IMPLIED>
	<!ENTITY web "web_developer">
	<!ENTITY dba "DBA">
]>

<empinfo>
	<employee>
		<designation discipline="&web;">Senior Engineer</designation>
	</employee>
	<employee>
		<designation discipline="&dba;">Administrator</designation>
	</employee>
</empinfo>

Run it...   »

Example Result:


ENTITIES

ENTITIES refer to a list of entity name separated by blank spaces.

Syntax :

<ATTLIST element_name attr_name ENTITIES attr_declaration>
<ENTITY entity_name entity_definition>
...

Example :

<?xml version="1.0" standalone="yes"?>
<!DOCTYPE empinfo [
	<!ELEMENT empinfo (employee)>
	<!ELEMENT employee (designation)>

	<!ELEMENT designation (#PCDATA)>
	<!ATTLIST designation discipline ENTITIES #IMPLIED>
	<!ENTITY web "web_developer">
	<!ENTITY dba "DBA">
	<!ENTITY soft "software_developer">
]>

<empinfo>
	<employee>
		<designation discipline="&web; &soft;">Senior Engineer</designation>
	</employee>
	<employee>
		<designation discipline="&dba;">Administrator</designation>
	</employee>
</empinfo>

Run it...   »

Example Result:


NMTOKEN

NMTOKEN specifies the any string character exclude whitespace. Before and after whitespace automatic trimmed.

Syntax :

<ATTLIST element_name attr_name NMTOKEN attr_declaration>

Example :

<?xml version="1.0" standalone="yes"?>
<!DOCTYPE empinfo [
	<!ELEMENT empinfo (employee)>
	<!ELEMENT employee (designation)>

	<!ELEMENT designation (#PCDATA)>
	<!ATTLIST designation discipline NMTOKEN "web_developer">
]>

<empinfo>
	<employee>
		<designation>Developer</designation>
	</employee>
	<employee>
		<designation discipline="DBA">Senior Engineer</designation>
	</employee>
	<employee>
		<designation discipline="software_developer">Administrator</designation>
	</employee>
</empinfo>

Run it...   »

Example Result:


NMTOKENS

NMTOKENS specifies the multiple NMTOKEN separated by whitespace.

Syntax :

<ATTLIST element_name attr_name NMTOKENS attr_declaration>

Example :

<?xml version="1.0" standalone="yes"?>
<!DOCTYPE empinfo [
	<!ELEMENT empinfo (employee)>
	<!ELEMENT employee (designation)>

	<!ELEMENT designation (#PCDATA)>
	<!ATTLIST designation discipline NMTOKENS "web_developer Trainee">
]>

<empinfo>
	<employee>
		<designation>Developer</designation>
	</employee>
	<employee>
		<designation discipline="DBA software_developer">Senior Engineer</designation>
	</employee>
</empinfo>

Run it...   »

Example Result: