public void parse(XMLStreamReader input) throws XMLStreamException, XNIException {
   if (input.hasNext()) {
     int eventType = input.getEventType();
     if (eventType != XMLStreamConstants.START_DOCUMENT
         && eventType != XMLStreamConstants.START_ELEMENT) {
       throw new XMLStreamException();
     }
     fLocationWrapper.setLocation(input.getLocation());
     fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null);
     boolean first = true;
     loop:
     while (input.hasNext()) {
       if (!first) {
         eventType = input.next();
       } else {
         first = false;
       }
       switch (eventType) {
         case XMLStreamConstants.START_ELEMENT:
           ++fDepth;
           fLocationWrapper.setLocation(input.getLocation());
           fNamespaceContext.setNamespaceContext(input.getNamespaceContext());
           fillQName(
               fElementQName, input.getNamespaceURI(), input.getLocalName(), input.getPrefix());
           fillXMLAttributes(input);
           fillDeclaredPrefixes(input);
           addNamespaceDeclarations();
           fNamespaceContext.pushContext();
           fSchemaDOMParser.startElement(fElementQName, fAttributes, null);
           break;
         case XMLStreamConstants.END_ELEMENT:
           fLocationWrapper.setLocation(input.getLocation());
           fNamespaceContext.setNamespaceContext(input.getNamespaceContext());
           fillQName(
               fElementQName, input.getNamespaceURI(), input.getLocalName(), input.getPrefix());
           fillDeclaredPrefixes(input);
           fSchemaDOMParser.endElement(fElementQName, null);
           fNamespaceContext.popContext();
           --fDepth;
           if (fDepth <= 0) {
             break loop;
           }
           break;
         case XMLStreamConstants.CHARACTERS:
           fTempString.setValues(
               input.getTextCharacters(), input.getTextStart(), input.getTextLength());
           fSchemaDOMParser.characters(fTempString, null);
           break;
         case XMLStreamConstants.SPACE:
           fTempString.setValues(
               input.getTextCharacters(), input.getTextStart(), input.getTextLength());
           fSchemaDOMParser.ignorableWhitespace(fTempString, null);
           break;
         case XMLStreamConstants.CDATA:
           fSchemaDOMParser.startCDATA(null);
           fTempString.setValues(
               input.getTextCharacters(), input.getTextStart(), input.getTextLength());
           fSchemaDOMParser.characters(fTempString, null);
           fSchemaDOMParser.endCDATA(null);
           break;
         case XMLStreamConstants.PROCESSING_INSTRUCTION:
           fillProcessingInstruction(input.getPIData());
           fSchemaDOMParser.processingInstruction(input.getPITarget(), fTempString, null);
           break;
         case XMLStreamConstants.DTD:
           /* There shouldn't be a DTD in the schema */
           break;
         case XMLStreamConstants.ENTITY_REFERENCE:
           /* Not needed for schemas */
           break;
         case XMLStreamConstants.COMMENT:
           /* No point in sending comments */
           break;
         case XMLStreamConstants.START_DOCUMENT:
           ++fDepth;
           /* We automatically call startDocument before the loop */
           break;
         case XMLStreamConstants.END_DOCUMENT:
           /* We automatically call endDocument after the loop */
           break;
       }
     }
     fLocationWrapper.setLocation(null);
     fNamespaceContext.setNamespaceContext(null);
     fSchemaDOMParser.endDocument(null);
   }
 }
 public void parse(XMLEventReader input) throws XMLStreamException, XNIException {
   XMLEvent currentEvent = input.peek();
   if (currentEvent != null) {
     int eventType = currentEvent.getEventType();
     if (eventType != XMLStreamConstants.START_DOCUMENT
         && eventType != XMLStreamConstants.START_ELEMENT) {
       throw new XMLStreamException();
     }
     fLocationWrapper.setLocation(currentEvent.getLocation());
     fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null);
     loop:
     while (input.hasNext()) {
       currentEvent = input.nextEvent();
       eventType = currentEvent.getEventType();
       switch (eventType) {
         case XMLStreamConstants.START_ELEMENT:
           ++fDepth;
           StartElement start = currentEvent.asStartElement();
           fillQName(fElementQName, start.getName());
           fLocationWrapper.setLocation(start.getLocation());
           fNamespaceContext.setNamespaceContext(start.getNamespaceContext());
           fillXMLAttributes(start);
           fillDeclaredPrefixes(start);
           addNamespaceDeclarations();
           fNamespaceContext.pushContext();
           fSchemaDOMParser.startElement(fElementQName, fAttributes, null);
           break;
         case XMLStreamConstants.END_ELEMENT:
           EndElement end = currentEvent.asEndElement();
           fillQName(fElementQName, end.getName());
           fillDeclaredPrefixes(end);
           fLocationWrapper.setLocation(end.getLocation());
           fSchemaDOMParser.endElement(fElementQName, null);
           fNamespaceContext.popContext();
           --fDepth;
           if (fDepth <= 0) {
             break loop;
           }
           break;
         case XMLStreamConstants.CHARACTERS:
           sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
           break;
         case XMLStreamConstants.SPACE:
           sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), true);
           break;
         case XMLStreamConstants.CDATA:
           fSchemaDOMParser.startCDATA(null);
           sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
           fSchemaDOMParser.endCDATA(null);
           break;
         case XMLStreamConstants.PROCESSING_INSTRUCTION:
           ProcessingInstruction pi = (ProcessingInstruction) currentEvent;
           fillProcessingInstruction(pi.getData());
           fSchemaDOMParser.processingInstruction(pi.getTarget(), fTempString, null);
           break;
         case XMLStreamConstants.DTD:
           /* There shouldn't be a DTD in the schema */
           break;
         case XMLStreamConstants.ENTITY_REFERENCE:
           /* Not needed for schemas */
           break;
         case XMLStreamConstants.COMMENT:
           /* No point in sending comments */
           break;
         case XMLStreamConstants.START_DOCUMENT:
           fDepth++;
           /* We automatically call startDocument before the loop */
           break;
         case XMLStreamConstants.END_DOCUMENT:
           /* We automatically call endDocument after the loop */
           break;
       }
     }
     fLocationWrapper.setLocation(null);
     fNamespaceContext.setNamespaceContext(null);
     fSchemaDOMParser.endDocument(null);
   }
 }