private final void buildElement(final String prefix, final String localName,
			final String namespaceURI, final boolean withpfx, boolean empty) throws XMLStreamException {
		
		if (document == null || done) {
			throw new XMLStreamException(
					"Cannot write new element when in current state.");
		}
		
		if (parent == document && document.hasRootElement()) {
			throw new XMLStreamException(
					"Document can have only one root Element.");
		}
			
		
		flushActiveElement();
		flushActiveText();
		
		// create an element-specific namespace binding layer.
		boundstack.push();
		
		final Namespace ns = resolveElementNamespace(prefix, namespaceURI, withpfx);

		final Element e = factory.element(localName, ns);

		factory.addContent(parent, e);
		activeelement = e;
		if (empty) {
			isempty = true;
		} else {
			isempty = false;
			parent = e;
		}
	}