/**
   * Scans a processing data. This is needed to handle the situation where a document starts with a
   * processing instruction whose target name <em>starts with</em> "xml". (e.g. xmlfoo)
   *
   * <p><strong>Note:</strong> This method uses fStringBuffer, anything in it at the time of calling
   * is lost.
   *
   * @param target The PI target
   * @param data The string to fill in with the data
   */
  protected void scanPIData(String target, XMLString data) throws IOException, XNIException {

    // check target
    if (target.length() == 3) {
      char c0 = Character.toLowerCase(target.charAt(0));
      char c1 = Character.toLowerCase(target.charAt(1));
      char c2 = Character.toLowerCase(target.charAt(2));
      if (c0 == 'x' && c1 == 'm' && c2 == 'l') {
        reportFatalError("ReservedPITarget", null);
      }
    }

    // spaces
    if (!fEntityScanner.skipSpaces()) {
      if (fEntityScanner.skipString("?>")) {
        // we found the end, there is no data
        data.clear();
        return;
      } else {
        if (fNamespaces && fEntityScanner.peekChar() == ':') {
          fEntityScanner.scanChar();
          XMLStringBuffer colonName = new XMLStringBuffer(target);
          colonName.append(":");
          String str = fEntityScanner.scanName();
          if (str != null) colonName.append(str);
          reportFatalError("ColonNotLegalWithNS", new Object[] {colonName.toString()});
          fEntityScanner.skipSpaces();
        } else {
          // if there is data there should be some space
          reportFatalError("SpaceRequiredInPI", null);
        }
      }
    }

    fStringBuffer.clear();
    // data
    if (fEntityScanner.scanData("?>", fStringBuffer)) {
      do {
        int c = fEntityScanner.peekChar();
        if (c != -1) {
          if (XMLChar.isHighSurrogate(c)) {
            scanSurrogates(fStringBuffer);
          } else if (isInvalidLiteral(c)) {
            reportFatalError("InvalidCharInPI", new Object[] {Integer.toHexString(c)});
            fEntityScanner.scanChar();
          }
        }
      } while (fEntityScanner.scanData("?>", fStringBuffer));
    }
    data.setValues(fStringBuffer);
  } // scanPIData(String,XMLString)
  /**
   * Scans a comment.
   *
   * <p>
   *
   * <pre>
   * [15] Comment ::= '&lt!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
   * </pre>
   *
   * <p><strong>Note:</strong> Called after scanning past '&lt;!--' <strong>Note:</strong> This
   * method uses fString, anything in it at the time of calling is lost.
   *
   * @param text The buffer to fill in with the text.
   */
  protected void scanComment(XMLStringBuffer text) throws IOException, XNIException {

    // System.out.println( "XMLScanner#scanComment# In Scan Comment" );
    // text
    // REVISIT: handle invalid character, eof
    text.clear();
    while (fEntityScanner.scanData("--", text)) {
      int c = fEntityScanner.peekChar();

      // System.out.println( "XMLScanner#scanComment#text.toString() == " + text.toString() );
      // System.out.println( "XMLScanner#scanComment#c == " + c );

      if (c != -1) {
        if (XMLChar.isHighSurrogate(c)) {
          scanSurrogates(text);
        }
        if (isInvalidLiteral(c)) {
          reportFatalError("InvalidCharInComment", new Object[] {Integer.toHexString(c)});
          fEntityScanner.scanChar();
        }
      }
    }
    if (!fEntityScanner.skipChar('>')) {
      reportFatalError("DashDashInComment", null);
    }
  } // scanComment()
  protected void scanPIData(String target, XMLStringBuffer data) throws IOException, XNIException {

    // check target
    if (target.length() == 3) {
      char c0 = Character.toLowerCase(target.charAt(0));
      char c1 = Character.toLowerCase(target.charAt(1));
      char c2 = Character.toLowerCase(target.charAt(2));
      if (c0 == 'x' && c1 == 'm' && c2 == 'l') {
        reportFatalError("ReservedPITarget", null);
      }
    }

    // spaces
    if (!fEntityScanner.skipSpaces()) {
      if (fEntityScanner.skipString("?>")) {
        // we found the end, there is no data just return
        return;
      } else {
        // if there is data there should be some space
        reportFatalError("SpaceRequiredInPI", null);
      }
    }

    // since scanData appends the parsed data to the buffer passed
    // a while loop would append the whole of parsed data to the buffer(data:XMLStringBuffer)
    // until all of the data is buffered.
    if (fEntityScanner.scanData("?>", data)) {
      do {
        int c = fEntityScanner.peekChar();
        if (c != -1) {
          if (XMLChar.isHighSurrogate(c)) {
            scanSurrogates(data);
          } else if (isInvalidLiteral(c)) {
            reportFatalError("InvalidCharInPI", new Object[] {Integer.toHexString(c)});
            fEntityScanner.scanChar();
          }
        }
      } while (fEntityScanner.scanData("?>", data));
    }
  } // scanPIData(String,XMLString)