Internal DTD Subsets

import java.math.BigInteger;
import java.io.*;
import org.jdom.*;
import org.jdom.output.XMLOutputter;


public class InternalValidFibonacci {

  public static void main(String[] args) {
   
    Element root = new Element("Fibonacci_Numbers");	
  	      
    BigInteger low  = BigInteger.ONE;
    BigInteger high = BigInteger.ONE;      
    
    for (int i = 1; i <= 25; i++) {
      Element fibonacci = new Element("fibonacci");
      Attribute index = new Attribute("index", String.valueOf(i));
      fibonacci.setAttribute(index);
      fibonacci.setText(low.toString());
      BigInteger temp = high;
      high = high.add(low);
      low = temp;
      root.addContent(fibonacci);
    }
 
    String dtd = "<!ELEMENT Fibonacci_Numbers (fibonacci*)>\r\n";
    dtd += "<!ELEMENT fibonacci (#PCDATA)>\r\n";
    dtd += "<!ATTLIST fibonacci index CDATA #IMPLIED>\r\n";

    DocType type = new DocType("Fibonacci_Numbers");
    type.setInternalSubset(dtd);
 
    Document doc = new Document(root, type);
    // serialize it into a file
    try {
      FileOutputStream out = new FileOutputStream("internalvalidfibonacci.xml");
      XMLOutputter serializer = new XMLOutputter(); 
      serializer.output(doc, out);
      out.flush();	
      out.close();
    }
    catch (IOException e) {
      System.err.println(e);
    }

  }

}
View Output in Browser
Previous | Next | Top | Cafe con Leche

Copyright 2000-2002 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified April 11, 2002