LinkedList<QName> stack = new LinkedList<QName>();
int depth = 0;
for (Object event : headEvents) {
if (event instanceof SAXStartElementEvent) {
SAXStartElementEvent startElementEvent = (SAXStartElementEvent) event;
String elementName = startElementEvent.getName();
QName element = new QName(prefix, elementName, elementName, uri);
stack.add(element);
XMLAttributes attrs = new XMLAttributesImpl();
for (Map.Entry<String, String> entry : startElementEvent.getAttributes().entrySet()) {
String name = entry.getKey();
String value = entry.getValue();
attrs.addAttribute(new QName(prefix, name, name, uri), "CDATA", value);
}