Sty - COMPUTER ENGINEERING
It's all about Internet, Security, Vulnerability, Programming, Networking, Software, and also Open Source Software. May this weblog can be your source of IT 's articles.
Showing posts with label DTD. Show all posts
Showing posts with label DTD. Show all posts

Before an application can read an XML document, it must learn what XML markup tags the document uses. It does this by reviewing the document type definition (DTD). A valid document includes a document type declaration that identifies the DTD the document satisfies. The DTD lists all the elements, attributes, and entities the document uses and the contexts in which it uses them.

Creating Your Own Markup Languages

When you create an XML document, you aren't really using XML to code the document. Instead, you are using a markup language that was created in XML. In other words, XML is used to create markup languages that are then used to create XML documents.

When you create your own markup language, you are basically establishing which elements (tags) and attributes are used to create documents in that language. Not only is it important to fully describe the different elements and attributes, but you must also describe how they relate to one another.

Creating Your First DTD

A DTD can be declared inline inside an XML document, or as an external reference.

Internal DTD Declaration

If the DTD is declared inside the XML file, it should be wrapped in a DOCTYPE definition with the following syntax:

<!DOCTYPE root-element [element-declarations]>

Example XML document with an internal DTD:

<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>

The DTD above is interpreted like this:

!DOCTYPE note defines that the root element of this document is note.
!ELEMENT note defines that the note element contains four elements: "to,from,heading,body".
!ELEMENT to defines the to element to be of the type "#PCDATA".
!ELEMENT from defines the from element to be of the type "#PCDATA".
!ELEMENT heading defines the heading element to be of the type "#PCDATA".
!ELEMENT body defines the body element to be of the type "#PCDATA".

External DTD Declaration

If the DTD is declared in an external file, it should be wrapped in a DOCTYPE definition with the following syntax:

<!DOCTYPE root-element SYSTEM "filename">

This is the same XML document as above, but with an external DTD (Open it, and select view source):

<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

And this is the file "note.dtd" which contains the DTD:

<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>

As you know by now, the goal of most XML documents is to be valid. Document validity is extremely important because it guarantees that the data within a document conforms to a standard set of guidelines as laid out in a schema (DTD or XSD).

An XML application can certainly determine if a document is well formed without any other information, but it requires a schema in order to assess document validity. This schema typically comes in the form of a DTD (Document Type Definition) or XSD (XML Schema Definition), which you learned about in next article.

To recap, schemas allow you to establish the following ground rules that XML documents must adhere to in order to be considered valid:

- Establish the elements that can appear in an XML document, along with the attributes that can be used with each
- Determine whether an element is empty or contains content (text and/or child elements)
- Determine the number and sequence of child elements within an element
- Set the default value for attributes

Sty - Knowledge is Free

Read More..

After you read my article few days ago, XML - Introduction to XML Programming, now you have an understanding of what XML is and how it works, it’s time to learn how to apply your knowledge and design your own set of XML markup tags, and then use those tags to write your first XML document. In this article, you’ll learn step-by-step how to do this, along with other design features, to build a working XML document that enables you to share information electronically among various applications.
This section follows an old programmer’s tradition of introducing a new language with a program that prints “Hello World” on the console. XML is a markup language, not a programming language; but the basic principle still applies. Let’s do that.

Creating a Simple XML Document

In this section, you’ll create a simple XML document and save it in a file. Code below is about the simplest XML document I can imagine, so start with it. You can type this document in any convenient text editor, such as Notepad, G-Edit, or Emacs.

Hello.xml

<?xml version=”1.0”?>
<root>
Hello XML!
</root>


That code is very simple, but it is a good XML document. To be more precise, it is a well-formed XML document. XML has special terms for documents that it considers “good” depending on exactly which set of rules they satisfy. “Well formed” is one of those terms, but we’ll get to that later.

Loading the XML File into a Web Browser

Now that you’ve created your first XML document, you’re going to want to look at it. You can open the file directly in a browser that supports XML such as Internet Explorer 5.0 or later. Figure at below shows the result; display Hello.xml in Internet Explorer 6.0.

XML in Browser

Congratulation you finally done your first XML document. Now you’re ready to continue for more advance topic of XML. Ha ha, it’s very little knowledge about XML, but it’s very useful to you, especially the root tag, so don’t be underestimate with those tag, I’ve tell you. See you in next article about XML, DTD – Document Type Definitions.

Sty – Knowledge is Free
Read More..

What is XML?

The following points can explain the purpose of XML.

  • XML stands for eXtensible Markup Language
  • XML is a markup language much like HTML.
  • XML was designed to describe data.
  • XML tags are not predefined in XML. You must define your own tags.
  • XML uses a DTD (Document Type Definition) to describe the data.
  • XML with a DTD is designed to be self describing.

It is important to understand that XML is not a replacement for HTML. The main purpose of HTML is the Format the Data that is presented through Browser. The purpose of XML is not to Format the Data to be displayed. It's mostly used to store and transfer data and to describe the data. It is device or language independent and can be used for Transmitting Data to any device. The Parser (Or the Program which is capable of understanding the Tags and returning the Text in a Valid Format) on the corresponding device will help in displaying the data in required format.

You can define your own tags in XML file. The way these tags will be interpreted will depend on the program which is going to get this XML file. The data embedded within these tags will be used according to logic implemented in the secondary program which is going to get this XML as feed. This point will be clearer when we start explaining you about how to use the Parsers in next few paragraphs.

XML Declarations

Most of the XML tags have a name associated with it. Here we explain different terms used to indicate the Elements defined in the XML file.

Well Formed Tags:

One of the most important features of a XML file is it should be a Well Formed File. What it means is all the tags should have a closing tag. In a HTML file, for some tags like <br> we don't have to specify a closing tag called </br>. Where as in a XML file, it is compulsory to have a closing tag. So we have to declare <br></br> or <br/>. This are what called as Well Formed Tags.

Elements and Attributes:

Each tag in a XML file can have elements and attributes. Here's how a typical tag looks like.

<Email
to="
admin@mydomain.com"
from=
"user@mySite.com"
subject="Introducing XML">

</Email>

In this example, Email is called as Element. This element called Email has three attributes, to, from and subject.

The Following Rules need to be followed while declaring the XML Elements Names:

  • Names can contain letters, numbers, and other characters
  • Names must not start with a number or "_" (underscore)
  • Names must not start with the letters xml (or XML or Xml ..)
  • Names can not contain spaces

Any name can be used, no words are reserved, but the idea is to make names descriptive. Names with an underscore separator are nice.

Examples: <author_name>, <published_date>.

Avoid "-" and "." in names. It could be a mess if your software tried to subtract name from first (author-name) or think that "name" is a property of the object "author" (author.name).

Element names can be as long as you like, but don't exaggerate. Names should be short and simple, like this: <author_name> not like this <name_of_the_author> .

XML documents often have a parallel database, where fieldnames parallel with element names. A good rule is to use the naming rules of your databases.

Non-English letters like éòá are perfectly legal in XML element names, but watch out for problems if your software vendor doesn't support it.

The ":" should not be used in element names because it is reserved to be used for something called namespaces.

Empty Tags:

In cases where you don't have to provide any sub tags, you can close the tag, by providing a "/" to the Closing Tag. For example declaring

<Text></Text> is same a declaring <Text/>

Comments in XML File:

Comments in XML file are declared the same way as Comments in HTML File.

<Text>Welcome To XML Tutorial</Text>
<!-- This is a comment -->
<Subject/>

The XML Prolog

XML file always starts with a prolog. The minimal prolog contains a declaration that identifies the document as an XML document, like this:

<?xml version="1.0"?>

The declaration may also contain additional information, like this:

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
  

The XML declaration may contain the following attributes:

version

Identifies the version of the XML markup language used in the data. This attribute is not optional.

encoding

Identifies the character set used to encode the data. "ISO-8859-1" is "Latin-1" the Western European and English language character set. (The default is compressed Unicode: UTF-8.).

standalone

Tells whether or not this document references an external entity or an external data type specification (see below). If there are no external references, then "yes" is appropriate.


Sty - Knowledge is Free

Read More..

Your Ad Here