/**
   * Write a new element with the specified name and attribute before the end element is written out
   *
   * @return the end element
   */
  private XMLEvent getAddedEventBeforeEndElement(
      XMLEvent event,
      XMLEventWriter writer,
      String elementName,
      String attributeName,
      String attributeValue)
      throws XMLStreamException {
    Attribute newAttribute = xmlEventFactory.createAttribute(attributeName, attributeValue);
    Set attributes = new HashSet();
    attributes.add(newAttribute);

    EndElement oldEvent = event.asEndElement();
    StartElement newStartEvent =
        xmlEventFactory.createStartElement(
            new QName(elementName), attributes.iterator(), oldEvent.getNamespaces());

    writer.add(newStartEvent);
    return xmlEventFactory.createEndElement(newStartEvent.getName(), newStartEvent.getNamespaces());
  }
 /** Fills in the list of declared prefixes. */
 private void fillDeclaredPrefixes(EndElement event) {
   fillDeclaredPrefixes(event.getNamespaces());
 }