protected org.w3c.dom.Document printDocument(final FormatStack fstack,
			final NamespaceStack nstack, final org.w3c.dom.Document basedoc,
			final Document doc) {

		if (!fstack.isOmitDeclaration()) {
			basedoc.setXmlVersion("1.0");
		}

		final int sz = doc.getContentSize();
		
		if (sz > 0) {
			for (int i = 0; i < sz; i++) {
				final Content c = doc.getContent(i);
				org.w3c.dom.Node n = null;
				switch (c.getCType()) {
					case Comment :
						n = printComment(fstack, basedoc, (Comment)c);
						break;
					case DocType :
						// cannot simply add a DocType to a DOM object
						// it is added when the DOM Document is created.
						// leave n as null
						break;
					case Element :
						n = printElement(fstack, nstack, basedoc, (Element)c);
						break;
					case ProcessingInstruction :
						n = printProcessingInstruction(fstack, basedoc, 
								(ProcessingInstruction)c);
						break;
					default :
						// do nothing.
				}
				if (n != null) {
					basedoc.appendChild(n);
				}
			}
		}
		
		return basedoc;
	}