How to Convert a XML String to Document Object


Document is an interface in org.w3c.dom package. It extents Node interface.  The domFactory.setNameSpaceAware()  method will have argument “true” as our parser produced will support XML namespace. In this example, we will give getDocFromXMLString() Method a String Argument. Please Note that this String Argument must be a  valid XML. The newDocumentBuilder will create new instance of DocumentBuilder with configured parameters. Then this String Argument will be Converted to Byte Array Input Stream.Then the builder.parse() method will take the Input Stream Argument to generate a Document Object. It is a good practice to close the streams in finally block.

You can find my other example to convert Dom / Document object to XML String here.

 Java example to Convert a XML String to DOM / Document Object


import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

public class StringToDocument {

	private static DocumentBuilderFactory domFactory = null;
	private static final String XMLString = "<DevelopProjects>
                                                     This is just a Sample XML String

	public static void main(String args[]) {
		domFactory = DocumentBuilderFactory.newInstance();
		try {
			Document doc = getDocFromXMLString(XMLString);
			System.out.println("Document is " + doc.getFirstChild());
		} catch (Exception e) {

	// Method to Convert a XML String to a Document Object.

	public static Document getDocFromXMLString(String xml) throws Exception {

		DocumentBuilder builder;
		Document doc;
		ByteArrayInputStream bis = null;
		try {
			builder = domFactory.newDocumentBuilder();
			bis = new ByteArrayInputStream(xml.getBytes());
			doc = builder.parse(bis);
		} catch (Exception exception) {
			System.out.println("Exception while generatign doc from xml string "
							+ exception);
			throw exception;
		} finally {
			try {
				if (bis != null) {
			} catch (IOException exception) {
				System.out.println("Exception while generatign doc from xml string "
								+ exception);
				throw exception;
		return doc;


Document Object Model

Document Interface




Two Way Communication Using Digital Signature

Two Way Communication Using Digital Signature

Today is the world of computers. Everyone is dependent on computers for communication. So communication threats are increasing day by day. Traditional means of communication without security has become vulnerable. So, a secured communication is necessary.

In our system, we have included many security mechanisms which can guard our transmitting data from all the security attacks. By using Digital signature we can protect our system from the most serious attack, denial of service that can’t be eliminated by ordinary means. In addition Digital signature provides Authentication and Integrity to the data. Whereas Encryption provides Confidentiality. These Security mechanisms guarantee the safe communication.

1.Java (JDK > 1.5)
2.Java Swing


                  1. Abstract

2. Software development environment

2.1. Java

3. Requirements analysis

3.1. Hardware requirements

3.2. Software requirements

3.3. Software requirement specifications

4. System design

4.1. Textual use case for client

4.2. Textual use case for server

4.3. UML diagrams

5. Testing strategies

5.8. Test case reports

6. Sample code

7. Screen shots

8. Conclusion

9. Bibliography