XML Validation

An XML Validator

To help you check the syntax of your XML files, we have created an XML validator to syntax-check your XML.


Valid XML Documents

A valid XML document is not the same as a well formed XML document.

The first rule, for a valid XML document, is that it must be well formed (see previous paragraph).

The second rule is that a valid XML document must conform to a document type.

Rules that defines legal elements and attributes for XML documents are often called document definitions, or document schemas.


When to Use a Document Definition?

A document definition is the easiest way to provide a reference to the legal elements and attributes of a document.

A document definition also provides a common reference that many users (developers) can share.

A document definition provides a standardization that makes life easier.


When NOT to Use a Document Definition?

XML does not require a document definition.

When you are experimenting with XML, or when you are working with small XML files, creating document definitions may be a waste of time.

If you develop applications, wait until the specification is stable before you add a document definition. Otherwise, your software might stop working because of validation errors.


Document Definitions

There are different types of document definitions that can be used with XML:

  • The original Document Type Definition (DTD)
  • The newer, and XML based, XML Schema

XML Elements vs Attributes

Usually elements are used to capture the data however attributes can be to capture the metadata (data about data – something that provides additional information about the data) ie the data which might not be used to display but can be used for search or other such features.There is no rule as such that says something should be an attribute or a element. I recommend to avoid it Winking smile

Some of the problems with using attributes are:

  • attributes cannot contain multiple values (elements can)
  • attributes cannot contain tree structures (elements can)
  • attributes are not easily expandable (for future changes)

Attributes are difficult to read and maintain. Use elements for data. Use attributes for information that is not relevant to the data.

The following three XML documents contain exactly the same information:

A date attribute is used in the first example:

<note date=”10/01/2008″>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don’t forget me this weekend!</body>
</note>

A date element is used in the second example:

<note>
<date>10/01/2008</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don’t forget me this weekend!</body>
</note>

An expanded date element is used in the third: Preferred :

<note>
<date>
<day>10</day>
<month>01</month>
<year>2008</year>
</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don’t forget me this weekend!</body>
</note>

Why dividing code into algorithms and coordinators

All code can be classified into two distinct roles; code that does work (algorithms) and code that coordinates work (coordinators).

The real complexity that gets introduced into a code bases is usually directly related to the creation of classes that group together both of these roles under one roof.

Computer electronics have two roles: doing work and binding together the stuff that does the work.  If you take out the CPU, the memory and all the other components that actually do some sort of work, you’ll be left with coordinators.  Wires and busses that bind together the components in the system.

So now that we understand that code could potentially be divided into two broad categories, the next question of course is why?  And can we even do it?

Let’s address why first.

The biggest benefit to pulling algorithmic code into separate classes from any coordinating code is that it allows the algorithmic code to be free of dependencies.  (Practically all dependencies.)

Once you free this algorithmic code of dependencies you’ll find 3 things immediately happen to that code:

  1. It becomes easier to unit test
  2. It becomes more reusable
  3. Its complexity is reduced

Remote Debug : Java Application using JDWP

Debugging application is always a common topic for all developers and it may cover more than 60%+ of total development time if using traditional way like using debugging message.

After the release of Sun Java Development Kit 1.4.2, you can be benefited by the magic tool called JDWP (Java Debugging Wire Protocol), It provides sophisticated implementation for debugging your JAVA application in a modern way, especially when you want to debug server java application like Tomcat, JBoss, etc..

Okay, you may say you are happy using debug message for debugging remote application and thus let me list the summary of how JDWP can aid the development.

  1. Thread stepping execution: Suspend/Resume particular thread
  2. Breakpoints management: Insert/Remove breakpoint for investigate failure point
  3. Hotswap Bug Fixing: Recompile the classes on-the-fly for bug fixing without redeployment

I thought you may be interested with the features 3, which greatly reduces the re-deployment time for debugging an application.

This articles will focus how the setup for debugging remote java application. Tomcat5.5 and Eclipse Europa will be used for an example.

1. High Level View

Basically it is divided into two entities: Debuggee and Debugger. The Debuggee is the application that you want to debug and for our example it is Tomcat. The Debugger is the vendor of JDI (Java Debugging Interface) : Eclipse.

jpda

 

2. Enable JDWP in the Debuggee (Tomcat)

JDWP can be enabled out of the box by setting the appropriate system properties :

-Xrunjdwp:transport=dt_socket,address=9002,server=y,suspend=n

This enables JVM with JDWP at port 9002 using server mode with any suspension.

Server

(“n” or “y”) If “y,” listen for a debugger application to attach; otherwise, attach to the debugger application at the specified address.

Address

transport address for the connection. If server=n, attempt to attach to a debugger application at this address. If server=y, listen for a connection at this address.

Timeout

If server=y, this specifies the timeout, in milliseconds, to wait for the debugger to attach. If server=n, this specifies the timeout, in milliseconds, to use when attaching to the debugger.

Suspend

If “y,” JVM suspends the execution until a debugger connects to the debuggee JVM. Preferably set this option to “n” else the application will not start unless the debugger attaches the port on which debugee  application is lessoning.

Remote Debug : an insight

remoteDebug

Some times you have to debug a application which is not running from it’s source code in a IDE. So to do it we use this remote debug concept. In the scenario which is shown above the application runs in a remote machine, but when it runs it will broadcast debug information via a socket deployed. The IDE running locally will capture those broadcast debug information through that socket and it will do the debug through the source code.
JAVA language provides this in its JVM. We can use commands like this to run a application in the remote debug mode in java.

java -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,suspend=n,server=y -jar Name_of_Your_Jar.jar

Then it will broadcast some debug information and will wait until some IDE capture those debug information and start debugging the source code. When Some IDE connects to the Socket specified it will start the debugging process.
Configuring the IDEs will depend on them. The links given below will give you a good understanding about those concepts. Hope you learn some thing from this post. Following links are really interesting to learn about remote debugging.

  • Application to be debugged would attach a socket to itself and then would listen debug instructions on that socket.
  • Debugger would bind itself to that socket and then send instructions on that socket.

What is Remote Debugging :
http://www.javabeat.net/2010/12/what-is-remote-debugging-in-java/
Remote Debugging with Eclipse :
http://www.eclipsezone.com/eclipse/forums/t53459.html
http://java.dzone.com/articles/how-debug-remote-java-applicat
http://www.myeclipseide.com/documentation/quickstarts/remotedebugging/
Remote Debugging with IntelliJ IDEA :
http://www.javaranch.com/journal/200408/DebuggingServer-sideCode.html
Remote Debugging Web Services, Apache Axis 2 :
http://wso2.org/library/225
http://wso2.org/library/3851
http://amilamanoj.blogspot.com/2011/09/running-debugging-apache-axis2-inside.html
http://shameerarathnayaka.blogspot.com/2011/09/remote-debugging-apache-axis2-with.html

Create War using command prompt

WAR stands for Web application ARchive. A Web application is a group of HTML pages, JSP pages, servlets, resources and source file, which can be managed as a single unit. A Web archive (WAR) file is a packaged(zipped/compressed) Web application. WAR files can be used to import a Web application into a Web server.

Here’s how to compress a ‘myWebApp’ web application into a “Web Archive” file named myWebApp.war so that you can easily transport it to another server.
* Open a command prompt and cd to
<Tomcat_home>\webapps\myWebApp
* Use the java archive command ‘jar’ to bundle up your application
jar -cvf myWebApp.war *

or go to one level before your web application folder  the folder you want to package as Web Archieve
you file is somewhere like d:\webapps\myWebApp
d:>cd webapps
d:\webapps:>jar -cvf myWebApp.war myWebApp

In English, “compress everything in this directory into a file named myWebApp.war”
(c=create, v=verbose, f=file)

Now you can copy myWebApp.war to any the webapps directory on a new Tomcat Server. When you save the file to a new server BE SURE not to save it as a ZIP file, choose “all files”. If Tomcat is running on the new server the war file will be automatically installed as soon as you save it. If not, start up Tomcat on the new server to install the application after you have saved it. Do NOT attempt to unzip the war file or do any installation yourself. Tomcat will do everything for you!

When the server is restarted it will automatically uncompress the files and recreate a web application named ‘myWebApp’.