/** Fills in the XMLAttributes object. */
 private void fillXMLAttributes(StartElement event) {
   fAttributes.removeAllAttributes();
   final Iterator attrs = event.getAttributes();
   while (attrs.hasNext()) {
     Attribute attr = (Attribute) attrs.next();
     fillQName(fAttributeQName, attr.getName());
     String type = attr.getDTDType();
     int idx = fAttributes.getLength();
     fAttributes.addAttributeNS(
         fAttributeQName, (type != null) ? type : XMLSymbols.fCDATASymbol, attr.getValue());
     fAttributes.setSpecified(idx, attr.isSpecified());
   }
 }
 /** Fills in the list of declared prefixes. */
 private void fillDeclaredPrefixes(StartElement event) {
   fillDeclaredPrefixes(event.getNamespaces());
 }
 final void validate(XMLEventReader reader, StAXResult result)
     throws SAXException, XMLStreamException {
   fCurrentEvent = reader.peek();
   if (fCurrentEvent != null) {
     int eventType = fCurrentEvent.getEventType();
     if (eventType != XMLStreamConstants.START_DOCUMENT
         && eventType != XMLStreamConstants.START_ELEMENT) {
       throw new SAXException(
           JAXPValidationMessageFormatter.formatMessage(
               fComponentManager.getLocale(), "StAXIllegalInitialState", null));
     }
     setup(null, result, false);
     fSchemaValidator.startDocument(fStAXLocationWrapper, null, fNamespaceContext, null);
     loop:
     while (reader.hasNext()) {
       fCurrentEvent = reader.nextEvent();
       eventType = fCurrentEvent.getEventType();
       switch (eventType) {
         case XMLStreamConstants.START_ELEMENT:
           ++fDepth;
           StartElement start = fCurrentEvent.asStartElement();
           fillQName(fElementQName, start.getName());
           fillXMLAttributes(start);
           fillDeclaredPrefixes(start);
           fNamespaceContext.setNamespaceContext(start.getNamespaceContext());
           fStAXLocationWrapper.setLocation(start.getLocation());
           fSchemaValidator.startElement(fElementQName, fAttributes, null);
           break;
         case XMLStreamConstants.END_ELEMENT:
           EndElement end = fCurrentEvent.asEndElement();
           fillQName(fElementQName, end.getName());
           fillDeclaredPrefixes(end);
           fStAXLocationWrapper.setLocation(end.getLocation());
           fSchemaValidator.endElement(fElementQName, null);
           if (--fDepth <= 0) {
             break loop;
           }
           break;
         case XMLStreamConstants.CHARACTERS:
         case XMLStreamConstants.SPACE:
           if (fStAXValidatorHandler != null) {
             Characters chars = fCurrentEvent.asCharacters();
             fStAXValidatorHandler.setIgnoringCharacters(true);
             sendCharactersToValidator(chars.getData());
             fStAXValidatorHandler.setIgnoringCharacters(false);
             fStAXValidatorHandler.characters(chars);
           } else {
             sendCharactersToValidator(fCurrentEvent.asCharacters().getData());
           }
           break;
         case XMLStreamConstants.CDATA:
           if (fStAXValidatorHandler != null) {
             Characters chars = fCurrentEvent.asCharacters();
             fStAXValidatorHandler.setIgnoringCharacters(true);
             fSchemaValidator.startCDATA(null);
             sendCharactersToValidator(fCurrentEvent.asCharacters().getData());
             fSchemaValidator.endCDATA(null);
             fStAXValidatorHandler.setIgnoringCharacters(false);
             fStAXValidatorHandler.cdata(chars);
           } else {
             fSchemaValidator.startCDATA(null);
             sendCharactersToValidator(fCurrentEvent.asCharacters().getData());
             fSchemaValidator.endCDATA(null);
           }
           break;
         case XMLStreamConstants.START_DOCUMENT:
           ++fDepth;
           if (fStAXValidatorHandler != null) {
             fStAXValidatorHandler.startDocument((StartDocument) fCurrentEvent);
           }
           break;
         case XMLStreamConstants.END_DOCUMENT:
           if (fStAXValidatorHandler != null) {
             fStAXValidatorHandler.endDocument((EndDocument) fCurrentEvent);
           }
           break;
         case XMLStreamConstants.PROCESSING_INSTRUCTION:
           if (fStAXValidatorHandler != null) {
             fStAXValidatorHandler.processingInstruction((ProcessingInstruction) fCurrentEvent);
           }
           break;
         case XMLStreamConstants.COMMENT:
           if (fStAXValidatorHandler != null) {
             fStAXValidatorHandler.comment((Comment) fCurrentEvent);
           }
           break;
         case XMLStreamConstants.ENTITY_REFERENCE:
           if (fStAXValidatorHandler != null) {
             fStAXValidatorHandler.entityReference((EntityReference) fCurrentEvent);
           }
           break;
         case XMLStreamConstants.DTD:
           DTD dtd = (DTD) fCurrentEvent;
           processEntityDeclarations(dtd.getEntities());
           if (fStAXValidatorHandler != null) {
             fStAXValidatorHandler.doctypeDecl(dtd);
           }
           break;
       }
     }
     fSchemaValidator.endDocument(null);
   }
 }