Monday, October 29, 2007

A trick

javascript: document.body.contentEditable = 'true'; document.designMode = 'on'; void 0

remember the code above.
Try to put them on firefox's address box, something weird is going to happen.


:0

Tuesday, October 23, 2007

Becareful of sakai-api

Sakai provides a functional api, which can be used to interact with other components of sakai, such as User-api.
One thing worth of noticing is that, when you try to use such an api, never bundle this jar file within your project (component); otherwise there will be a conflict between the api within your project and sakai's.

Thursday, October 18, 2007

You can use Spring Framework to inject the service or use the cover:

1. Using Spring to get the service for your class (e.g. YourAppClass) (recommended)
1.1). Add the UserDirectoryService bean to the bean for YourAppClass


<bean id="org.sakaiproject.yourapp.logic.YourAppClass"
class="org.sakaiproject.yourapp.logic.impl.YourAppClassImpl">
<property name="userDirectoryService"
ref="org.sakaiproject.user.api.UserDirectoryService" />
</bean>


1.2). Add a variable and setter to YourAppClass to use the service in like so:

private UserDirectoryService userDirectoryService;
public void setUserDirectoryService(UserDirectoryService userDirectoryService) {
this.userDirectoryService = userDirectoryService;
}


2. Using the cover to get the service
* Note: This is not the recommended method, you should be using Spring to inject the service
2.1). Setup a variable to hold the instance from the cover

private UserDirectoryService userDirectoryService;


2.2). Get access to the service using the cover

userDirectoryService = org.sakaiproject.user.cover.UserDirectoryService.getInstance();






ATTENTION:: If you're using the first method, you should be sure of that your project is following sakai's structure, especially the bean's id.
I am using the second one.

Using Sakai API

In my case, the most useful object is the "user", because I need to identify who is the manager, and who is common member having merely the "access" ability:
Click here to know more.

first, get a "UserDirectoryService" via Spring Injection;
Then, use (UserDirectoryService) uds.getCurrentUser;
And now, we get a current user. With org.sakaiproject.user.api, we can know more about the operations on it.

Click here to know more SAKAI TIPS.

Wednesday, October 17, 2007

the "fmt" exception has been solved

It is amazingly easy.
What I need to do is to modify my "include.jsp" as:

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>


<%@ include file="/WEB-INF/jsp/sakai.jsp" %>>
<body onload="<%= request.getAttribute("sakai.html.body.onload")%>;foobar()">




now, it should be working, no fmt exception at all.

Wednesday, October 3, 2007

Here comes Java file structure

  • org.sakaiproject.app-name
    • dao
      all dao api classes
      • impl
        all dao implementation classes
    • hbm
      hibernate mapping files only
    • logic
      all business logic api classes
      • impl
        all business logic implementation classes
    • model
      all value object POJOs
    • service (cannot use public)
      all publically accessible api classes related to the app
    • tool
      all java classes related to the tool (backing beans)
      • jsf, producers, params
        presentation specific classes related to the tool

Note: You may have your own package base instead of org.sakaiproject

File Structure

When develop a Sakai project, its structure is a thing worthy of concerning. Here it is:
  • app-name
    • api - project with all interfaces, model objects, and hibernate hbm files
      Deploy as a jar to shared [ no dependencies ]
      (optional) eclipse .project here (name the project -api)
      • src - includes interfaces, model objects, and hbm files
      • test - (optional) may include shared test data and mock objects which help other with tests
    • impl - project at this level
      Deploy as a jar, include in pack [api]
      (optional) eclipse .project here (name the project -impl)
      • src - includes java source for all implementations of apis
      • test - includes all unit and integration tests
    • pack - project for components stuff needed by Sakai (should just a set of spring config files)
      Deploy to components [impl (all in war bundle)]
    • tool - project for the tool (interface to the user)
      Deploy as a war [api]
      (optional) eclipse .project here (name the project -tool)
      • src - java src directory
        • java - any java code used for the tool only
        • webapp
          • app-name - JSF jsp files here
          • css
          • images
          • templates - RSF html templates
          • tools - Sakai tool.xml files goes in here
          • WEB-INF - lots of xml config files here (web.xml, applicationContext.xml, etc...
project.xml hints listed below each directory in italics, dependencies are in []

Sunday, September 30, 2007

about MySQL4.1.22

My sakai is running on MySql4.1.22.
Here are some tips worth of memorizing:

-2. Unzip mysql4.1.22 package to a proper directory, say "/opt/mysql4.1.22", which equals to {MySQL_HOME}

-1.set ${MySQL_HOME} into ${PATH};

0. run "${MySQL_HOME}/configure" first;

1.(*** !!!that's it!!! ***) About socket error "ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)"
-- if this occurs, no need to do anything but kill the process "mysqld", and wait until no mysql processes are running;

2. set "root" user if you didn't -- using command "mysql -u root password mysqlpwd1";

3. run mysql.

Thursday, September 20, 2007

Equals and HashCode

Java's Collections and Relational database (and thus Hibernate) relies heavily on being able to distinguish objects in a unified way. In Relational database's this is done with primary keys, in Java we have equals() and hashCode() methods on the objects. This page tries to discuss the best strategies for implementation of equals() and hashcode() in your persistent classes.
Why are equals() and hashcode() important
Normally, most Java objects provide a built-in equals() and hashCode() based on the object's identity; so each new() object will be different from all others.
This is generally what you want in ordinary Java programming. And if all your objects are in memory, this is a fine model. Hibernate's whole job, of course, is to move your objects out of memory. But Hibernate works hard to prevent you from having to worry about this.
Hibernate uses the Hibernate session to manage this uniqueness. When you create an object with new(), and then save it into a session, Hibernate now knows that whenever you query for an object and find that particular object, Hibernate should return you that instance of the object. And Hibernate will do just that.
However, once you close the Hibernate session, all bets are off. If you keep holding onto an object that you either created or loaded in a Hibernate session that you have now closed, Hibernate has no way to know about those objects. So if you open another session and query for "the same" object, Hibernate will return you a new instance. Hence, if you keep collections of objects around between sessions, you will start to experience odd behavior (duplicate objects in collections, mainly).
The general contract is: if you want to store an object in a List, Map or a Set then it is an requirement that equals and hashCode are implemented so they obey the standard contract as specified in the documentation.

to read more, please refer to [http://www.hibernate.org/109.html]

Wednesday, September 19, 2007

hierarchy of properties files

In fact, Maven has a hierarchy of properties files which you can use to customize a build for a specific project or a specific user. Maven reads properties from the following sources, in the order shown:

${basedir}/project.properties
This file is a sibling to both maven.xml and project.xml. This file customizes behavior for a particular project.

${basedir}/build.properties
This file is also a sibling to maven.xml and project.xml, but this file is used to customize a specific project's build for a specific user. If you need to change the value of a property for your own build environment but you don't want to affect the properties of other users, add a build.properties file to ${basedir}. Values defined in this file will override values defined in project.properties. build.properties should not be checked into source control; this file is for an individual user to tailor the behavior of a specific project.

${user.home}/build.properties
Your home directory can contain a build.properties file which contains user-specific properties to be used on all projects. This is the proper file in which to configure properties for a proxy server or a remote repository. Properties defined in this file are read for every project, and they supersede the values set in the previous two files.

System properties (specified with the -D flag)
Setting the value of a property on the command line supersedes all other configuration files. This is the final stop for properties.

Thursday, September 13, 2007

Using 3rd party plugins in maven

tomcat-plugin can be download from
http://www.codeczar.com/maven.

I did this manually, because when I ran the command
"maven-DartifactId=maven-tomcat-plugin -DgroupId=codeczar-tomcat -Dversion=1.2.1plugin:download"
what downloaded was just a broken file named"maven-tomcat-plugin-1.2.1.jar"(28kb).
[or, google the jar file to find the correct repository]

Maven 1.0.2 Structure

A project that uses the WAR plug-in contains three source trees:




src/main

Contains the runtime Java sources.



src/test

Contains the JUnit tests for unit testing the Java code found in src/main. Note that these unit tests are performed in isolation (i.e., without a running container). They are not functional tests.




src/webapp

Contains all the web application resources (HTML files, JSP files, configuration files, etc.). For the web subproject you have only a WEB-INF/web.xml file, which maps the Servlet to a web context.

Sunday, September 2, 2007

Check back on my project~

These 2 weeks were spent on my project, a web-based calender combined with ToDo list.
The component's are prepared. The next job will be to connect them together, and inject them into Spring-Hibernate framework.
Hope that I can handle this, as soon as possible.
Time, my biggest barrier...

Using an Eclipse plugin for Maven

There are two ways to use Maven and Eclipse:
1. Eclipse as the editor, and Maven command line for commands, or
2. Using an Eclipse plugin for Maven
Use the first one if you're much more comfortable with using the command line for your maven executions, but would like to take advantage of eclipse' features ( code complete, refactoring, etc ). Use the second one if you want eclipse to handle all these things - creation to editing to execution.

To do so, you must install an eclipse plugin for maven. For example, to install the m2eclipse plugin, go to

Help > Software Updates > Find and Install > Search for new features to install.

Then from there, clicked on the "New Remote Site" button and enter a name ( i.e m2eclipse ) and the url "http://m2eclipse.codehaus.org/". Then just click "next" till you reach "finish".

Maven, not just another build tool

In the Maven world, a project product (jar, war, ...) is called an artifact. Every project generates one and only one primary artifact (secondary artifacts will be covered in more advanced trails). An artifact is always identified by two ids:

groupId It identifies your project as a whole (it will make more sense when you start using multi-modules build) and should be unique. Maven enforces a naming schema following the Java package name rules. Hence, the groupId has to start by at least a domain name you control followed by any subgroups you want. For further informations, look at The package names in the Java language. [characters restrictions]
An example: org.apache.maven

artifactId It identifies precisely the current project inside the group identified by the groupId. [characters restrictions]
An example: groupdId: org.apache.maven.doxia, artifactId: doxia

and a version:

version: The version number allows you to distinguish your different project releases. There are two kinds of versions depending of the release type it is associated with:
Official releases : 1.0, 2.2, ...
Specific releases (nightly build or snapshots) : 1.0-SNAPSHOT, 2.1.2-SNAPSHOT [characters restrictions]

Having precise naming formats allows Maven to manage efficiently for you the dependencies and the plugins your project depends upon. We'll see what that means in the next lessons.
REF::http://docs.codehaus.org/display/MAVENUSER/Maven%2C+not+just+another+build+tool

Friday, August 17, 2007

Reflections on Java Reflection - part 3

There is a nice little land mine hidden in getConstructor. When you are specifying the parameter types for the constructor you are looking for, you need to carefully distinguish between a primitive argument and the related object based wrapper. Does the constructor take as an argument the primitive int or its uncle, a object of class java.lang.Integer? If you are looking for a constructor that takes the object wrapper type, something like java.lang.Integer, just use the wrapper class, Integer.class If you mean the primitive int you will need use Integer.TYPE, which is a sort of placeholder for the class that the primitive lacks. All of the wrapper classes have a static TYPE field which you can use to indicate a primitive of that type.


Digging Deeper into A Class

As you saw in the first example, a Class object can supply you with all of the basic information about a class, things like its name and super class. But you can go way beyond this name, rank and serial number level of information. You can, for example, find out about all of the public methods supported by a class with the getMethods method:

Class klass = Class.forName("com.russolsen.reflect.Employee");

Method[] methods = klass.getMethods();

for(Method m : methods )
{
System.out.println( "Found a method: " + m );
}

getMethods returns an array of Method objects, one for each public method that instances of the class will answer to:

Found a method: public java.lang.String com.russolsen.reflect.Employee.toString()
Found a method: public int com.russolsen.reflect.Employee.getSalary()
Found a method: public void com.russolsen.reflect.Employee.setSalary(int)
Found a method: public native int java.lang.Object.hashCode()
Found a method: public final native java.lang.Class java.lang.Object.getClass()
Found a method: public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
Found a method: public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
Found a method: public final void java.lang.Object.wait() throws java.lang.InterruptedException
Found a method: public boolean java.lang.Object.equals(java.lang.Object)
Found a method: public java.lang.String java.lang.Object.toString()
Found a method: public final native void java.lang.Object.notify()
Found a method: public final native void java.lang.Object.notifyAll()

Since getMethods takes a client's view of the class, the array will contains all of the public methods, including those defined in the class itself and in its super class and its super-duper class and so on up to Object.

If you are interested in a single method, you can use getMethod (note that it is singular), which works a lot like getConstructor, except that you need to pass in a method name as well as the parameter types. The code below looks for a method called setSalary that takes a single int parameter:

Class klass = Class.forName("com.russolsen.reflect.Employee");
Class[] paramTypes = {Integer.TYPE };
Method setSalaryMethod =
klass.getMethod("setSalary", paramTypes);

System.out.println( "Found method: " + setSalaryMethod);

Calling a method via reflection turns out to be very similar calling a constructor. All you need is the Method object that we talked about earlier, an array of arguments to pass to the method and the instance whose method you are calling. The code below calls the setSalary method on an Employee object to give our man a raise:

Class klass = Class.forName("com.russolsen.reflect.Employee");

Class[] paramTypes = {Integer.TYPE };
Method setSalaryMethod =
klass.getMethod("setSalary", paramTypes);

Object theObject = klass.newInstance();
Object[] parameters = { new Integer(90000) };

setSalaryMethod.invoke(theObject, parameters);

Why would you bother going through all of this instead of just typing theObject.setSalary(90000)? Well, take another look at the code above. Other than the string on the first line, the program above is completely generic: you could use it to call the setSalary method on any instance of any class. With a little rearrangement, you can use the code above to call any method on any class.
Messing with Fields

You are not limited to just calling methods via reflection: you also have full reign over fields. Similar to getMethods, getFields returns an array of Field objects, one for each public instance field supplied by the class or its super classes:

Class klass = Class.forName("com.russolsen.reflect.Employee");

System.out.println( "Class name: " + klass.getName());

Field[] fields = klass.getFields();

for(Field f : fields )
{
System.out.println( "Found field: " + f);
}

Since Employee has exactly two public fields, you get a two member array back:

Class name: com.russolsen.reflect.Employee
Found field: public java.lang.String com.russolsen.reflect.Employee._firstName
Found field: public java.lang.String com.russolsen.reflect.Employee._lastName

You can also look for a specific field by name with the getField method:

Field field = klass.getField("_firstName");
System.out.println("Found field: " + field);

Once you have a Field object, getting the field value is as simple as calling the get method, while setting the value is just a call to set away:


Object theObject = new Employee("Tom", "Smith", 25);

Class klass = Class.forName("com.russolsen.reflect.Employee");

Field field = klass.getField("_firstName");

Object oldValue = field.get(theObject);
System.out.println( "Old first name is: " + oldValue);

field.set( theObject, "Harry");
Object newValue = field.get(theObject);
System.out.println( "New first name is: " + newValue);

Run the code above and watch the value of the _salary field change before your very eyes:

Old first name is: Tom
New first name is: Harry

Breaking the Rules

No look at reflection can be complete without talking about how to break one of the most sacred of all the rules in Java. Everyone knows that you cannot call a private method from outside of the class that defines it. Right? Well you can't if you stick to conventional techniques, but with reflection you can do darn near anything.

The first thing you need to call a private method is the Method instance that goes with the method you want to call. You can't get this from getMethod; it only returns public methods. The way to get hold of a private (or protected) method is to use getDeclaredMethod. While getMethod takes a client's view of a class and only returns public methods, getDeclaredMethod returns all of the methods declared by one class. In the example below, we use it to get at the Method object for the very private removeRange method on the java.util.ArrayList class:

ArrayList list = new ArrayList();
list.add("Larry");
list.add("Moe");
list.add("Curley");

System.out.println("The list is: " + list);

Class klass = list.getClass();

Class[] paramTypes = { Integer.TYPE, Integer.TYPE };
Method m = klass.getDeclaredMethod("removeRange", paramTypes);

Object[] arguments = { new Integer(0), new Integer(2) };
m.setAccessible(true);
m.invoke(list, arguments);
System.out.println("The new list is: " + list);

Once you have a private method, calling it is a simple matter of clicking off the final setAccessable safety and having at it:

The list is: [Larry, Moe, Curley]
The new list is: [Curley]

The removeRange method appears to remove the given range of items from the list. This is pretty strong voodoo: you just reached in and called a private method on a java.util class. Would you want to make a habit of circumventing the clear intent of the code and calling private methods? No! But such things have been known to come in handy in a pinch.
Conclusion

Reflection allows your programs to do things that seem to defy the rules of Java. You can write code that can find out all about a class to which it has never been properly introduced. And your code can act on that dynamically discovered knowledge: it can create new instances, call methods and set and get the value of fields. In extreme circumstances you can even mess with the private internals of a class. A good understanding of reflection is what you need to grasp the workings of some of the more sophisticated tools of the Java world; it is also what you need to write programs that go beyond what "ordinary" Java programs can do.
Resources

* Reflection tutorial
* In depth article about reflection from IBM's developerWorks

Russ Olsen is currently a senior engineer with FGM, where he builds information systems with both J2EE and Rails. Russ spends a lot of his otherwise free time writing about technology.

Reflections on Java Reflection - part 2

As the example shows, getting the class name and super-class is as easy as calling some accessors. If you are interested in knowing if the class is public or abstract or final, the process is only slightly more complicated. All of this information comes packaged up in a single int returned by getModifiers. Fortunately, Java supplies you with the Modifier class, which is contains a bunch of static methods that will help you make sense of the number returned by getModifiers.


Calling getClass on an instance is not the only way to get hold of a class object. You can also get it directly from a class name:

Class klass = Employee.class;

The third way of getting hold of a class is the interesting one: you can create a Class object from a string -- well only if that string happens to contain the name of a class. The way to do this is to call the forName class method on Class:

Class klass = Class.forName("com.russolsen.reflect.Employee");

System.out.println( "Class name: " + klass.getName());
System.out.println(
"Class super class: " + klass.getSuperclass());

// Print out the rest...

One thing to keep in mind about forName is that you need to supply the full, complete with the package, name of the class. Plain old "Employee" will not do, it has to be "com.russolsen.reflect.Employee". With forName we begin to get a glimpse at some of the fundamental power (and coolness) of the reflection API: you can start with a class name in a string and end up with the class.
Instances Instantly

Getting hold of a class and finding all about it is interesting and useful in its own right, but actually doing something with it is where reflection gets really exciting. The most obvious thing to do with a Class object is to make a new instance of that class. The simple way to do this is with the newInstance method. To show all this in action, the little program below takes a command line argument (which should contain a class name) creates a class from it and then makes a new instance of that class:

package com.russolsen.reflect;

public class NewInstanceExample
{
public static void main(String[] args)
throws ClassNotFoundException,
InstantiationException, IllegalAccessException
{

Class klass = Class.forName(args[0]);
Object theNewObject = klass.newInstance();
System.out.println("Just made: " + theNewObject);
}
}

Run the code above with "com.russolsen.reflect.Employee" as an argument and you will manufacture a brand new Employee object:

Just made: Employee: John Smith 50000

Run it again, but this time feed it "java.util.Date" and you will get:

Just made: Tue Feb 27 20:25:20 EST 2007

Think about how much flexibility you get with just a few lines of code: the program above really knows nothing about Employee or Date and yet it can create a new instance of either. This is a different way of doing Java.
Beyond the no-args Constructor

It turns out that calling the Class.newInstance method is identical to doing an ordinary new with no arguments. But what happens if you call newInstance on a class that lacks a no argument constructor? Nothing good: you are in for an unpleasant InstantiationException.

The good news is that you can dynamically create new instances of a class that requires constructor arguments -- you just have to work a bit harder. What you need to do is to find the constructor that you need from the class and call it with the right arguments. The way to find the constructor of your dreams is to call the getConstructor method with a description of the constructor that you are looking for. What you will get back is a Constructor object, which you can use to create a new instance.

Let's see how this all works in code:

Class klass = Class.forName("com.russolsen.reflect.Employee");

Class[] paramTypes = {
String.class,
String.class,
Integer.TYPE };

Constructor cons = klass.getConstructor(paramTypes);

System.out.println( "Found the constructor: " + cons);


Object[] args = {
"Fred",
"Fintstone",
new Integer(90000) };

Object theObject = cons.newInstance(args);
System.out.println( "New object: " + theObject);

The only difference between the constructors are the parameters they take, so the way that you tell getConstructor which constructor you are looking for is to pass it an array of Class's, one for each parameter. The example above goes looking for a constructor that takes two strings and an int. Once you have a Constructor, creating a new object instance with it is very simple: you just call the newInstance method, passing in another array, this time an array full of the actual argument values.

Reflections on Java Reflection - part 1

In ordinary life, a reflection is what you see when you look in the mirror. In the world of programming, reflection is what you call it when a program looks at and possibly even modifies its own structure. The Java reflection API allows you to do exactly that by giving you a window into the fundamental features of the language -- classes and fields and methods -- via an ordinary Java API. Understanding reflection will help you understand the tools that you use every day. How does Eclipse manage to do all that helpful auto-completion of method names? How does Tomcat go from a class name in a web.xml file to a running servlet fielding web requests? And how does Spring do all of that magic dependency injection stuff? In your own programs, you can use reflection to write code that is more flexible and dynamic: with reflection your program can cope gracefully with classes it has never met before.
Conjuring Up A Class

As I said, the fundamental idea of reflection is to give you an ordinary Java API into the inner workings of your program. Since the most basic idea in Java is the class (try to write a Java program without one), a good place to start is by looking at the Class class. No, that is not a typing stutter: you can actually get hold of an object which contains everything you might ever need to know about a Java class. That object will have a type of Class. Once you have a Class instance, you can extract all kinds of information about the class from it, including the name of the class, whether it is public or abstract or final, and even its super-class.

Enough theory: let's turn our reflection microscope on the following, very simple Employee class:

package com.russolsen.reflect;

public class Employee
{
public String _firstName;
public String _lastName;
private int _salary;

public Employee()
{
this( "John", "Smith", 50000);
}

public Employee(String fn, String ln, int salary)
{
_firstName = fn;
_lastName = ln;
_salary = salary;
}

public int getSalary()
{
return _salary;
}

public void setSalary(int salary)
{
_salary = salary;
}

public String toString()
{
return "Employee: " + _firstName + " "
+ _lastName + " " + _salary;
}

}

The easiest way to get a class object is to just ask an object instance for its class with the getClass method. The code below creates a Employee instance, asks for its class, and prints out various bits of information about the class:

package com.russolsen.reflect;

import java.lang.reflect.Modifier;

public class GetClassExample
{
public static void main(String[] args)
{

Employee employee = new Employee();

Class klass = employee.getClass();

System.out.println( "Class name: " + klass.getName());
System.out.println(
"Class super class: " + klass.getSuperclass());

int mods = klass.getModifiers();
System.out.println(
"Class is public: " + Modifier.isPublic(mods));
System.out.println(
"Class is final: " + Modifier.isFinal(mods));
System.out.println(
"Class is abstract: " + Modifier.isAbstract(mods));

}

}

Run the code above and you will see something like:

Class name: com.russolsen.reflect.Employee
Class super class: class java.lang.Object
Class is public: true
Class is final: false
Class is abstract: false

Sunday, August 5, 2007

HOW XML WORKS???

[http://xml.silmaril.ie/]

What is XML?

[http://xml.silmaril.ie/basics/whatisxml/]

XML is the Extensible Markup Language. It improves the functionality of the Web by letting you identify your information in a more accurate, flexible, and adaptable way.

It is extensible because it is not a fixed format like HTML (which is a single, predefined markup language). Instead, XML is actually a metalanguage—a language for describing other languages—which lets you design your own markup languages for limitless different types of documents. XML can do this because it's written in SGML, the international standard metalanguage for text document markup (ISO 8879).


How to control formatting and appearance?

[http://xml.silmaril.ie/authors/style/]

In HTML, default styling was built into the browsers because the tagset of HTML was predefined and hardwired into browsers. In XML, where you can define your own tagset, browsers cannot possibly be expected to guess or know in advance what names you are going to use and what they will mean, so you need a stylesheet if you want to display formatted text.

Browsers which read XML will accept and use a CSS stylesheet at a minimum, but you can also use the more powerful XSLT stylesheet language to transform your XML into HTML—which browsers, of course, already know how to display (and that HTML can still use a CSS stylesheet). This way you get all the document management benefits of using XML, but you don't have to worry about your readers needing XML smarts in their browsers.


What's a Document Type Definition (DTD)?

[http://xml.silmaril.ie/authors/dtds/]

A DTD is a description in XML Declaration Syntax of a particular type or class of document. It sets out what names are to be used for the different types of element, where they may occur, and how they all fit together. (A question C.16, Schema does the same thing in XML Document Syntax, and allows more extensive data-checking.)

For example, if you want a document type to be able to describe Lists which contain Items, the relevant part of your DTD might contain something like this:


<!ELEMENT List (Item)+>



<!ELEMENT Item (#PCDATA)>


This defines a list as an element type containing one or more items (that's the plus sign); and it defines items as element types containing just plain text (Parsed Character Data or PCDATA). Validators read the DTD before they read your document so that they can identify where every element type ought to come and how each relates to the other, so that applications which need to know this in advance (most editors, search engines, navigators, and databases) can set themselves up correctly. The example above lets you create lists like:


<List>

<Item>Chocolate</Item>

<Item>Music</Item>

<Item>Surfing</Item>

</List>

(The indentation in the example is just for legibility while editing: it is not required by XML.)

A DTD provides applications with advance notice of what names and structures can be used in a particular document type. Using a DTD and a validating editor means you can be certain that all documents of that particular type will be constructed and named in a consistent and conformant manner.

DTDs are not required for processing the tip in question Bwell-formed documents, but they are needed if you want to take advantage of XML's special attribute types like the built-in ID/IDREF cross-reference mechanism; or the use of default attribute values; or references to external non-XML files (‘Notations’); or if you simply want a check on document validity before processing.

There are thousands of DTDs already in existence in all kinds of areas (see the SGML/XML Web pages for pointers). Many of them can be downloaded and used freely; or you can write your own (see the question on creating your own DTD. Old SGML DTDs need to be converted to XML for use with XML systems: read the question on converting SGML DTDs to XML, but most popular SGML DTDs are already available in XML form.

New Some XML editors use a binary compiled format of DTD produced by their own management routines to allow a single person in an organisation to be in charge of modifications, and to distribute only an unmodifiable (binary compiled) version to users.

The alternatives to a DTD are various forms of question C.16, Schema. These provide more extensive validation features than DTDs, including character data content validation.





Tuesday, July 24, 2007

!!! Hello World, ebus5003 !!!

It is very hard too say something before starting this subject; however, trying my best is what I am going to do about it.

Greetings, every friend!

After hibernating, will come the spring.
The Gang of Four, laugh at me.
I am foolish, or ...?
Hoping 15 out of the 21 will be enough..

Oops, here we go!