qaengine/src/XMLTree.cxx
//-----------------------------------------------------------------------------------------
// This method reads XML data from the valid file handle and generates tree nodes.
//-----------------------------------------------------------------------------------------
This method reads XML data from the valid file handle and generates tree nodes.
This method reads XML data from the valid file handle and generates tree nodes .
int XMLTree::parseXML(istream& in) {
char   ch;
int    inTag    = 0;
int    closeTag = 0;
char   prevCh=0;
string tag;
string val;
  while(!in.eof()) {
	  in.read(&ch,1);
	  if(ch=='\n') continue;
	  if(prevCh=='<' && ch=='/') {
		  closeTag=1;
	  }
	  if(ch=='<') {
		  if(val.length()>0) {
			  if(val.length()>0) appendTextNode(val);
			  val="";
		  }
		  prevCh = ch;
		  inTag = 1;
		  continue;
	  }
	  if(ch=='>') {
		  if(!closeTag) {
			  if(prevCh=='/') tag.erase(tag.length()-1,1);
			  if(tag.length()>0)
			      appendTagNode(tag);
			  if(prevCh=='/') closeTagNode();
		  } else{
			  closeTagNode();
		  }
		  tag="";
		  inTag   = 0;
		  closeTag = 0;
		  prevCh = ch;
		  continue;
	  }
	  prevCh = ch;
	  if(inTag) { 
		  if(tag.length()>0 || ch!=' ') tag+=ch;
	  } else {
		  if(val.length()>0 || ch!=' ') val+=ch;
	  }
  } 
  return 0;
}
int XMLTree :: parseXML ( istream & in ) { char ch ; int inTag = 0 ; int closeTag = 0 ; char prevCh = 0 ; string tag ; string val ; while ( ! in . eof ( ) ) { in . read ( & ch , 1 ) ; if ( ch == ' \n ' ) continue ; if ( prevCh == ' ' && ch == ' ' ) { closeTag = 1 ; } if ( ch == ' ' ) { if ( val . length ( ) > 0 ) { if ( val . length ( ) > 0 ) appendTextNode ( val ) ; val = " " ; } prevCh = ch ; inTag = 1 ; continue ; } if ( ch == ' ' ) { if ( ! closeTag ) { if ( prevCh == ' ' ) tag . erase ( tag . length ( ) - 1 , 1 ) ; if ( tag . length ( ) > 0 ) appendTagNode ( tag ) ; if ( prevCh == ' ' ) closeTagNode ( ) ; } else { closeTagNode ( ) ; } tag = " " ; inTag = 0 ; closeTag = 0 ; prevCh = ch ; continue ; } prevCh = ch ; if ( inTag ) { if ( tag . length ( ) > 0 || ch != ' ' ) tag += ch ; } else { if ( val . length ( ) > 0 || ch != ' ' ) val += ch ; } } return 0 ; }
This method reads XML data from the valid file handle and generates tree nodes.
This method reads XML data from the valid file handle and generates tree nodes .