src/lib/Parser.js
/**
  Consumes a processing instruction if possible.

  @returns {boolean}
    Whether a processing instruction was consumed.

  @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-pi
  */
Consumes a processing instruction if possible.
Consumes a processing instruction if possible .
consumeProcessingInstruction() {
    let { scanner } = this;
    let mark = scanner.charIndex;
    if (!scanner.consumeStringFast('<?')) {
      return false;
    }
    let name = this.consumeName();
    if (name) {
      if (name.toLowerCase() === 'xml') {
        scanner.reset(mark);
        this.error("XML declaration isn't allowed here");
      }
    } else {
      this.error('Invalid processing instruction');
    }
    if (!this.consumeWhitespace()) {
      if (scanner.consumeStringFast('?>')) {
        this.addNode(new XmlProcessingInstruction(name));
        return true;
      }
      this.error('Whitespace is required after a processing instruction name');
    }
    let content = scanner.consumeUntilString('?>');
    this.validateChars(content);
    if (!scanner.consumeStringFast('?>')) {
      this.error('Unterminated processing instruction');
    }
    this.addNode(new XmlProcessingInstruction(name, content));
    return true;
  }
consumeProcessingInstruction ( ) { let { scanner } = this ; let mark = scanner . charIndex ; if ( ! scanner . consumeStringFast ( '<?' ) ) { return false ; } let name = this . consumeName ( ) ; if ( name ) { if ( name . toLowerCase ( ) === 'xml' ) { scanner . reset ( mark ) ; this . error ( "XML declaration isn't allowed here" ) ; } } else { this . error ( 'Invalid processing instruction' ) ; } if ( ! this . consumeWhitespace ( ) ) { if ( scanner . consumeStringFast ( '?>' ) ) { this . addNode ( new XmlProcessingInstruction ( name ) ) ; return true ; } this . error ( 'Whitespace is required after a processing instruction name' ) ; } let content = scanner . consumeUntilString ( '?>' ) ; this . validateChars ( content ) ; if ( ! scanner . consumeStringFast ( '?>' ) ) { this . error ( 'Unterminated processing instruction' ) ; } this . addNode ( new XmlProcessingInstruction ( name , content ) ) ; return true ; }
Consumes a processing instruction if possible.
Consumes a processing instruction if possible .