private char[] parseEntityReference() throws IOException {
  int pos=strpos;
  if ((ch=readCh()) == '#') {
    int n=0;
    ch=readCh();
    if ((ch >= '0') && (ch <= '9') || ch == 'x' || ch == 'X') {
      if ((ch >= '0') && (ch <= '9')) {
        while ((ch >= '0') && (ch <= '9')) {
          n=(n * 10) + ch - '0';
          ch=readCh();
        }
      }
 else {
        ch=readCh();
        char lch=(char)Character.toLowerCase(ch);
        while ((lch >= '0') && (lch <= '9') || (lch >= 'a') && (lch <= 'f')) {
          if (lch >= '0' && lch <= '9') {
            n=(n * 16) + lch - '0';
          }
 else {
            n=(n * 16) + lch - 'a' + 10;
          }
          ch=readCh();
          lch=(char)Character.toLowerCase(ch);
        }
      }
switch (ch) {
case '\n':
        ln++;
      ch=readCh();
    lfCount++;
  break;
case '\r':
ln++;
if ((ch=readCh()) == '\n') {
ch=readCh();
crlfCount++;
}
 else {
crCount++;
}
break;
case ';':
ch=readCh();
break;
}
char data[]=mapNumericReference(n);
return data;
}
addString('#');
if (!parseIdentifier(false)) {
error("ident.expected");
strpos=pos;
char data[]={'&','#'};
return data;
}
}
 else if (!parseIdentifier(false)) {
char data[]={'&'};
return data;
}
boolean semicolon=false;
switch (ch) {
case '\n':
ln++;
ch=readCh();
lfCount++;
break;
case '\r':
ln++;
if ((ch=readCh()) == '\n') {
ch=readCh();
crlfCount++;
}
 else {
crCount++;
}
break;
case ';':
semicolon=true;
ch=readCh();
break;
}
String nm=getString(pos);
Entity ent=dtd.getEntity(nm);
if (!strict && (ent == null)) {
ent=dtd.getEntity(nm.toLowerCase());
}
if ((ent == null) || !ent.isGeneral()) {
if (nm.length() == 0) {
error("invalid.entref",nm);
return new char[0];
}
String str="&" + nm + (semicolon ? ";" : "");
char b[]=new char[str.length()];
str.getChars(0,b.length,b,0);
return b;
}
return ent.getData();
}

private char [ ] parseEntityReference ( ) throws IOException { int pos = strpos ; if ( ( ch = readCh ( ) ) == '#' ) { int n = 0 ; ch = readCh ( ) ; if ( ( ch >= '0' ) && ( ch <= '9' ) || ch == 'x' || ch == 'X' ) { if ( ( ch >= '0' ) && ( ch <= '9' ) ) { while ( ( ch >= '0' ) && ( ch <= '9' ) ) { n = ( n * 10 ) + ch - '0' ; ch = readCh ( ) ; } } else { ch = readCh ( ) ; char lch = ( char ) Character . toLowerCase ( ch ) ; while ( ( lch >= '0' ) && ( lch <= '9' ) || ( lch >= 'a' ) && ( lch <= 'f' ) ) { if ( lch >= '0' && lch <= '9' ) { n = ( n * 16 ) + lch - '0' ; } else { n = ( n * 16 ) + lch - 'a' + 10 ; } ch = readCh ( ) ; lch = ( char ) Character . toLowerCase ( ch ) ; } } switch ( ch ) { case '\n' : ln ++ ; ch = readCh ( ) ; lfCount ++ ; break ; case '\r' : ln ++ ; if ( ( ch = readCh ( ) ) == '\n' ) { ch = readCh ( ) ; crlfCount ++ ; } else { crCount ++ ; } break ; case ';' : ch = readCh ( ) ; break ; } char data [ ] = mapNumericReference ( n ) ; return data ; } addString ( '#' ) ; if ( ! parseIdentifier ( false ) ) { error ( "ident.expected" ) ; strpos = pos ; char data [ ] = { '&' , '#' } ; return data ; } } else if ( ! parseIdentifier ( false ) ) { char data [ ] = { '&' } ; return data ; } boolean semicolon = false ; switch ( ch ) { case '\n' : ln ++ ; ch = readCh ( ) ; lfCount ++ ; break ; case '\r' : ln ++ ; if ( ( ch = readCh ( ) ) == '\n' ) { ch = readCh ( ) ; crlfCount ++ ; } else { crCount ++ ; } break ; case ';' : semicolon = true ; ch = readCh ( ) ; break ; } String nm = getString ( pos ) ; Entity ent = dtd . getEntity ( nm ) ; if ( ! strict && ( ent == null ) ) { ent = dtd . getEntity ( nm . toLowerCase ( ) ) ; } if ( ( ent == null ) || ! ent . isGeneral ( ) ) { if ( nm . length ( ) == 0 ) { error ( "invalid.entref" , nm ) ; return new char [ 0 ] ; } String str = "&" + nm + ( semicolon ? ";" : "" ) ; char b [ ] = new char [ str . length ( ) ] ; str . getChars ( 0 , b . length , b , 0 ) ; return b ; } return ent . getData ( ) ; }
parse an entity reference . [ 59 ] 350 : 17
