Beruflich Dokumente
Kultur Dokumente
The First line is xml declaration which defines the xml version. The next
line is the root element of the document. All xml documents must have the
root element to mark the beginning and end of the document. The next
three lines are the child elements.
Example for Elements and Attributes:
<?xml version="1.0"?>
<Student>
<Stream type="BCA">
<Duration>3 Years</Duration>
<Fee>1,80,000/-</Fee>
</Stream>
<Stream type="MCA">
<Duration>3 Years</Duration>
<Fee>1,86,000/-</Fee>
</Stream>
</Student>
XML tag names can’t start with xml, XML or Xml etc. Names can
contain letters, numbers and characters but can’t start with a
number. Names can’t have spaces.
Validating XML
Document Type Definition (DTD)
XML Schema
DTD
A DTD defines the structure and the legal elements and
attributes of an XML document so that independent groups of
people can agree on a standard DTD for interchanging data. An
application can use a DTD to verify that XML data is valid.
Internal DTD Declaration
<?xml version="1.0"?>
<!DOCTYPE Student [
<!ELEMENT Student (Stream, Duration, Fee)>
<!ELEMENT Stream (#PCDATA)>
<!ELEMENT Duration (#PCDATA)>
<!ELEMENT Fee (#PCDATA)>
<!ATTLIST Stream type CDATA "">
]>
<Student>
<Stream type="MCA">Master of Computer Application</Stream>
<Duration>3 Years</Duration>
<Fee>1,80,000/-</Fee>
</Student>
External DTD Declaration
<?xml version="1.0"?>
<!DOCTYPE Student SYSTEM “xyz.dtd">
<Student>
<Stream type=“BCA”>Bachelor of Computer Application</Stream>
<Duration>3 Years</Duration>
<Fee>1,80,000/-</Fee>
</Student> xyz.dtd
<!ELEMENT Student (Stream, Duration, Fee)>
<!ELEMENT Stream (#PCDATA)>
<!ELEMENT Duration (#PCDATA)>
<!ELEMENT Fee (#PCDATA)>
<!ATTLIST Stream type CDATA “”>
The DTD above is interpreted like this:
!DOCTYPE Student defines that the root element of this document is note
!ELEMENT Student defines that the Student element must contain four
elements: “Stream, Duration, Fee"
!ELEMENT Stream defines the Stream element to be of type "#PCDATA"
!ELEMENT Duration defines the Duration element to be of type
"#PCDATA"
!ELEMENT Fee defines the Fee element to be of type "#PCDATA“
!ATTLIST Stream Type defines the attribute Type to be of type CDATA.
PCDATA
PCDATA means parsed character data that will be parsed by a
parser. The text will be examined by the parser for entities and
markup. Tags inside the text will be treated as markup and
entities will be expanded. However, parsed character data should
not contain any &, <, or > characters; these need to be
represented by the & < and > entities, respectively.
CDATA
CDATA means character data. CDATA is text that will
not be parsed by a parser. Tags inside the text will not
be treated as markup and entities will not be expanded.