private String [ ] readXMLDeclaration ( Reader r ) throws KNXMLException { final StringBuffer buf = new StringBuffer ( 100 ) ; try { for ( int c = 0 ; ( c = r . read ( ) ) != - 1 && c != ' ' ; ) buf . append ( ( char ) c ) ; } catch ( final IOException e ) { throw new KNXMLException ( "reading XML declaration, " + e . getMessage ( ) , buf . toString ( ) , 0 ) ; } String s = buf . toString ( ) . trim ( ) ; String version = null ; String encoding = null ; String standalone = null ; for ( int state = 0 ; state < 3 ; ++ state ) if ( state == 0 && s . startsWith ( "version" ) ) { version = getAttValue ( s = s . substring ( 7 ) ) ; s = s . substring ( s . indexOf ( version ) + version . length ( ) + 1 ) . trim ( ) ; } else if ( state == 1 && s . startsWith ( "encoding" ) ) { encoding = getAttValue ( s = s . substring ( 8 ) ) ; s = s . substring ( s . indexOf ( encoding ) + encoding . length ( ) + 1 ) . trim ( ) ; } else if ( state == 1 || state == 2 ) { if ( s . startsWith ( "standalone" ) ) { standalone = getAttValue ( s ) ; if ( ! standalone . equals ( "yes" ) && ! standalone . equals ( "no" ) ) throw new KNXMLException ( "invalid standalone pseudo-attribute" , standalone , 0 ) ; break ; } } else throw new KNXMLException ( "unknown XML declaration pseudo-attribute" , s , 0 ) ; return new String [ ] { version , encoding , standalone } ; }
returns array with length 3 and optional entries version encoding standalone