// if there is any printable content, or if expandempty is set
// then we must expand.
boolean expandit = walker != null || fstack.isExpandEmptyElements();
if (expandit) {
Namespace ns = element.getNamespace();
if (ns == Namespace.NO_NAMESPACE) {
out.writeStartElement(element.getName());
} else if ("".equals(ns.getPrefix())) {
out.writeStartElement(ns.getURI(), element.getName());
} else {
out.writeStartElement(ns.getPrefix(), element.getName(), ns.getURI());
}
// Print the element's namespace, if appropriate
for (final Namespace nsd : nstack.addedForward()) {
printNamespace(out, fstack, nsd);
}
// Print out attributes
if (element.hasAttributes()) {
for (final Attribute attribute : element.getAttributes()) {
printAttribute(out, fstack, attribute);
}
}
// OK, now we print out the meat of the Element
if (walker != null) {
// we need to re-create the walker/fstack.
fstack.push();
try {
fstack.setTextMode(textmode);
if (!walker.isAllText() && fstack.getPadBetween() != null) {
// we need to newline/indent
final String indent = fstack.getPadBetween();
printText(out, fstack, new Text(indent));
}
printContent(out, fstack, nstack, walker);
if (!walker.isAllText() && fstack.getPadLast() != null) {
// we need to newline/indent
final String indent = fstack.getPadLast();
printText(out, fstack, new Text(indent));
}
} finally {
fstack.pop();
}
}
out.writeEndElement();
} else {
// implies:
// fstack.isExpandEmpty... is false
// and content.isEmpty()
// or textonly == true
// and preserve == false
// and whiteonly == true
Namespace ns = element.getNamespace();
if (ns == Namespace.NO_NAMESPACE) {
out.writeEmptyElement(element.getName());
} else if ("".equals(ns.getPrefix())) {
out.writeEmptyElement("", element.getName(), ns.getURI());
} else {
out.writeEmptyElement(ns.getPrefix(), element.getName(), ns.getURI());
}
// Print the element's namespace, if appropriate
for (final Namespace nsd : nstack.addedForward()) {
printNamespace(out, fstack, nsd);