tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 XML > XOM > Add Doctype

Add Doctype 

XOM (XML Object Model) is a tree based java API for processing XML by taking the best ideas from SAX and DOM. It is simple, fast and easy to use. This requires the library xom-1.2.7.jar to be in classpath. The following example shows adding document type element to an XML.

File Name  :  

File Name  :  
Author  :  Sudhakar KV
Email  :  [email protected]
package com.bethecoder.tutorials.xom.tests;


import nu.xom.Builder;
import nu.xom.DocType;
import nu.xom.Document;
import nu.xom.ParsingException;
import nu.xom.ValidityException;

public class AddDocType {

   @param args
   @throws IOException 
   @throws ParsingException 
   @throws ValidityException 
  public static void main(String[] argsthrows ValidityException, ParsingException, IOException {
    Builder builder = new Builder();
    InputStream ins = AddDocType.class.getClassLoader()
    //Reads and parses the XML
    Document doc =;

    //Add doc type to XML
    DocType doctype = new DocType("Random_Numbers""randoms.dtd");
      doc.insertChild(doctype, 0);


It gives the following output,
File Name  :  OUTPUT



Books Recommendation

bl  br