You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by David --- <da...@yahoo.fr> on 2004/03/02 10:22:36 UTC

xerces 2.5 Problems with transcode and also with get*Count functions

Hi,
I'm trying to implement a saxparser and got some
problems when trying to parse the files.Actually I
have an xml factory object which return the appropiate
parser (Dom or SAX2) according to what the user
specifies. The final idea is to parse an XML file, and
get some specific tags but first i wanted to try to
count the different elements based on the SAX2Count
sample.

Here below the output of the program, i added some
controls to make sure everything is ok.
Also note that the counts I do are wrong. Only the
getCharacterCount() returns the correct number of
characters, the other count functions return 0. I'm
quite new with Xml so forgive me if it is not very
clear.
david


david@>SaxParsing_classtest example.xml
Calling Sax Parser
Constructor XML called ok
Xml platform initiated
Trying to instantiate SAXParser
SAXParser instantiated ok
Trying to parse example.xml...

Error at file 0x8077960, line 1, char 15
  Message: 0x8077918

Error at file 0x8078368, line 2, char 17
  Message: 0x8078320

Error at file 0x80784b8, line 2, char 25
  Message: 0x8078430

-----
-----
-----

Elements0
Attributes0
Spaces0
Characters2347
Parsing done successfully.
SAXParser destruction done
Destructor XML called ok
Xml platform terminated
Done
>


Here below the code i guess is affected:

void SaxParser::ParseFile(char *xmlFile)
{
    std::cout <<"Trying to parse "<< xmlFile << "..."
<< std::endl;
    
    // handle errors
    c_parser->setErrorHandler(this);
    c_parser->setContentHandler(this);

    try {
	c_parser->parse(xmlFile);
    }
    catch (const XMLException& e) {
	std::cout << "\nError during parsing: "<< xmlFile
		  << "Exception message is: \n"
		  << Error(e.getMessage())<< std::endl ;
	
	
    }
    if (!this->getSawErrors()){
// 	std::cout << "Element" <<
handler.getElementCount() << std::endl;
// 	std::cout << "Attributes" <<
handler.getAttrCount()<< std::endl;
// 	std::cout << "Spaces" << handler.getSpaceCount()<<
std::endl;
// 	std::cout << "Characters" <<
handler.getCharacterCount() << std::endl;
 	std::cout << "Element" << this->getElementCount() <<
std::endl;
	std::cout << "Attributes" << this->getAttrCount()<<
std::endl;
	std::cout << "Spaces" << this->getSpaceCount()<<
std::endl;
	std::cout << "Characters" <<
this->getCharacterCount() << std::endl;
    }
    

######
Here the Error object i use
  
class Error {

 public:
    //
-----------------------------------------------------------------------
    //  Constructors and Destructor
    //
-----------------------------------------------------------------------
    
    Error(const XMLCh* const toTranscode)
	{
	    // Call the private transcoding method
	    char * errormessage =
XMLString::transcode(toTranscode);
	}
    
    ~Error()
	{
	    XMLString::release(&errormessage);
	}

     //
-----------------------------------------------------------------------
    //  Getter methods
    //
-----------------------------------------------------------------------
      
    const char* displayerror() const
	{
	    return errormessage;
	}

private :
    char* errormessage;
};


inline XERCES_STD_QUALIFIER ostream&
operator<<(XERCES_STD_QUALIFIER ostream& target, const
Error& Dump)
{
    target << Dump.displayerror();
    return target;
}

#endif





	

	
		
Yahoo! Mail : votre e-mail personnel et gratuit qui vous suit partout ! 
Créez votre Yahoo! Mail sur http://fr.benefits.yahoo.com/

Dialoguez en direct avec vos amis grâce à Yahoo! Messenger !Téléchargez Yahoo! Messenger sur http://fr.messenger.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org