Hi,
Without seeing all your code it is difficult to say why it won't compile.
Do you define your own writeChars method? The XMLFormatTarget class has a
pure virtual method for writeChars so you would need to implement it
yourself, I didn't see it in what you posted. Also the invokation of
XMLFormatter is commented out in the code you posted - is that what is
causing the error so you commented it out or is there another call to
XMLFormatter?
David
David ---
<[EMAIL PROTECTED]
fr> To
xerces-c-dev@xml.apache.org
01/21/2005 05:18 cc
AM
Subject
Xml::Formatter help need
Please respond to
xerces-c-dev
Hello,
I have written a sax parser that implements xerces-c.
if i declare in my Xml.h the public XMLFormatTarget i
get can't compile (see error below).
However if i compile but don't implement in the class
the XMLFormatTarget it compiles and works properly.
Does anybody know what is the problem ???
thanks
[XmlXercesFactory]# make clean all
rm -f *.o *~ SaxParsing_classtest *.a *core*
*.xml *.xml_parsed
g++ -g -w -O2 -L/usr/local/lib XmlFactory.cpp -c -o
XmlFactory.o
g++ -g -w -O2 -L/usr/local/lib SaxParser.cpp -c -o
SaxParser.o
g++ -g -w -O2 -L/usr/local/lib DomParser.cpp -c -o
DomParser.o
g++ -g -w -O2 -L/usr/local/lib Xml.cpp -c -o Xml.o
/usr/local/include/xercesc/framework/XMLFormatter.hpp:
In constructor `Xml::Xml()':
/usr/local/include/xercesc/framework/XMLFormatter.hpp:412:
error: `xercesc_2_6::XMLFormatter::XMLFormatter()' is
private
Xml.cpp:5: error: within this context
make: *** [Xml.o] Error 1
I have different files show below:
***********
XMLFactory.h
***********
#include "Xml.h"
#include "DomParser.h"
#include "SaxParser.h"
class XmlFactory {
public:
XmlFactory(std::string v,bool d, bool n, bool s,
bool fs, std::string e);
/*
* Sets the appropiate xml parser defined by user
* 2 possiblities:
* Dom: Domparser works with a copy in memory of the
file
* Sax: reads the xmlfile without keeping anything in
memory*/
Xml* setParser(std::string type);
virtual ~XmlFactory();
// -----------------------------
##############################
Xml.h
##############################
#ifndef XML_H
#define XML_H
#ifndef XERCES_CPP_NAMESPACE_USE
#define XERCES_CPP_NAMESPACE_USE
#endif
//Std libs
#include <iostream>
#include <string>
#include <vector>
//Required for XmlParsing
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/parsers/SAXParser.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/framework/XMLPScanToken.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/XMLUni.hpp>
#include <xercesc/sax/AttributeList.hpp>
#include <xercesc/sax2/SAX2XMLReader.hpp>
#include <xercesc/sax2/XMLReaderFactory.hpp>
#include <xercesc/sax2/DefaultHandler.hpp>
#include <xercesc/sax2/Attributes.hpp>
#include <xercesc/util/XMLChTranscoder.hpp>
#include <xercesc/framework/XMLFormatter.hpp>
#include <xercesc/util/XMemory.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
#include <xercesc/util/TransService.hpp>
#include "Transcode.h"
#This declaration of the class doesn't work
class Xml : public DefaultHandler, public
XMLFormatTarget {
//The declaration below works
//class Xml : public DefaultHandler {
public:
/*
* Constructor
*/
/*XmlParser(XercesDOMParser *parser) ;*/
Xml();
virtual ~Xml();
......
override xerces functions here....
....
#############################################
SaxParser.h
############################################
SaxParser::SaxParser(std::string v,bool d, bool n,
bool s, bool fs, std::string e)
{
std::cout << "Trying to instantiate SAXParser" <<
std::endl;
// bool fExpandNS ;
// XMLFormatter *Formatter;
// XMLFormatter::UnRepFlags UnRepFlags =
XMLFormatter::UnRep_CharRef;
// bool expandNamespaces= false ;
// const char * encode = strdup(e.c_str());
// // XMLTranscoder *transcoder = new
XMLTranscoder();
// // const XMLCh* test =
transcoder->getEncodingName();
// // XMLRecognizer::Encodings fEncoding;
// try {
// Formatter = new XMLFormatter(encode , this ,
XMLFormatter::NoEscapes, UnRepFlags);
// }
// catch (const XMLException& ex) {
// std::cout << "ERROR MESSAGE:"
// << Error(ex.getMessage()) <<"\n";
// exit(0);
// }
// std::cout << Formatter->getEncodingName() <<
std::endl;
// exit(0);
doNamespaces = n;
doSchema = s;
schemaFullChecking = fs;
Validation_scheme = strdup(v.c_str()) ;
// This is useful for validating DTD files if
required
//requires access to the dtd file ,defined in the
header of xml file
loadexternaldtd = d;
if (strcasecmp(Validation_scheme,"always") == 0)
{
SAX2XMLReader::ValSchemes valScheme =
SAX2XMLReader::Val_Always;
}
else if(strcasecmp(Validation_scheme,"never") ==
0)
{
SAX2XMLReader::ValSchemes valScheme =
SAX2XMLReader::Val_Never;
}
else
{
SAX2XMLReader::ValSchemes valScheme =
SAX2XMLReader::Val_Auto;
}
//std::cout << "DTD:"<< d << " NS:" <<doNamespaces
<< " Schema:" << doSchema << " FS:" <<
schemaFullChecking << " Val:" << Validation_scheme <<
std::endl;
try {
c_parser = XMLReaderFactory::createXMLReader();
}
catch (const XMLException& ex) {
std::cout << "Error during Sax2Xmlreader
parsing:\n"
<< Error(ex.getMessage()) << "\n";
}
// catch (const OutOfMemoryException&)
// {
// XERCES_STD_QUALIFIER cerr <<
"OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
// }
c_parser->setErrorHandler(this);
c_parser->setContentHandler(this);
//c_parser->setFeature(XMLUni::fgSAX2CoreValidation,CoreValidation);
c_parser->setFeature(XMLUni::fgSAX2CoreNameSpaces,
doNamespaces);
c_parser->setFeature(XMLUni::fgXercesSchema,
doSchema);
c_parser->setFeature(XMLUni::fgXercesSchemaFullChecking,
schemaFullChecking);
c_parser->setFeature(XMLUni::fgXercesLoadExternalDTD,
loadexternaldtd);
std::endl;
######################
Classtest.cpp
#####################
....main....
char *xmlFile = strdup((arg.getParam(1).c_str()));
//Set the parser to use. See class doc for more
info
string type = "sax";
XmlFactory xmlf(c_v ,c_d ,c_n ,c_s ,c_fs ,c_e);
Xml *parser = xmlf.setParser(type);
......
Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos
mails !
Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]