// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;

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

import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import org.apache.xml.serialize.XMLSerializer;

public class DomTest7 {
   public static void main(String[] args) {
      try {
         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
         DocumentBuilder db = dbf.newDocumentBuilder();
         Document doc = db.newDocument();
         Element game = doc.createElement("game");
         doc.appendChild(game);
         Element isTaking = doc.createElement("isTaking");
         Attr isTakingAttr = doc.createAttribute("type");
         isTakingAttr.setValue("boolean");
         isTaking.setAttributeNode(isTakingAttr);
         isTaking.appendChild(doc.createTextNode("true"));
         game.appendChild(isTaking);
         Element player = doc.createElement("player");
         Attr playerAttr = doc.createAttribute("type");
         playerAttr.setValue("int");
         player.setAttributeNode(playerAttr);
         player.appendChild(doc.createTextNode("1"));
         game.appendChild(player);
         XMLSerializer ser = new XMLSerializer(System.out, null);
         ser.serialize(doc.getDocumentElement());
      } catch (FactoryConfigurationError e) {
         e.printStackTrace();
      } catch (ParserConfigurationException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
      return;
   }
}
