@@ -32,7 +32,7 @@ public Element(String outerHTML) throws Exception {
3232 int ws = -1 ;
3333 for (int z =0 ; z <outerHTML .length (); z ++){
3434 char t = outerHTML .charAt (z );
35- if (Parser . isBlank (t )){
35+ if (isWhitespace (t )){
3636 ws = z +1 ;
3737 break ;
3838 }
@@ -42,28 +42,28 @@ public Element(String outerHTML) throws Exception {
4242 //Get position of the first ">" character
4343 int gt = Parser .findGT (0 , outerHTML +" " );
4444 if (gt ==-1 ) throw new Exception ("Invalid or unsupported html" ); //includes html comments
45-
45+ gt ++;
4646
4747
4848 //Set nodeName and attributes
49- int endNodeName ;
49+ int endNode ;
5050 if (ws ==-1 ){
51- endNodeName = gt -1 ;
51+ endNode = gt -1 ;
5252 attributes = "" ;
5353 }
5454 else {
5555 if (gt <ws ){
56- endNodeName = gt -1 ;
56+ endNode = gt -1 ;
5757 attributes = "" ;
5858 }
5959 else {
60- endNodeName = ws ;
61- attributes = outerHTML .substring (endNodeName , gt -1 ).trim ();
60+ endNode = ws ;
61+ attributes = outerHTML .substring (endNode , gt -1 ).trim ();
6262 if (attributes .endsWith ("/" )) attributes = attributes .substring (0 , attributes .length ()-1 ).trim ();
6363 }
6464
6565 }
66- nodeName = outerHTML .substring (1 , endNodeName );
66+ nodeName = outerHTML .substring (1 , endNode );
6767 if (nodeName .endsWith ("/" )) nodeName = nodeName .substring (0 , nodeName .length ()-1 );
6868 nodeName = nodeName .trim ();
6969
@@ -366,4 +366,18 @@ else if (newTag.charAt(i+1)=='\''){
366366 }
367367 return "" ;
368368 }
369+
370+
371+ //**************************************************************************
372+ //** isWhitespace
373+ //**************************************************************************
374+ /** Returns true if the given char is a white space, tab or return
375+ */
376+ private static boolean isWhitespace (char c ){
377+ if (c ==' ' ) return true ;
378+ if (c =='\r' ) return true ;
379+ if (c =='\n' ) return true ;
380+ if (c =='\t' ) return true ;
381+ return false ;
382+ }
369383}
0 commit comments