本文整理汇总了C++中QXmlSimpleReader::setFeature方法的典型用法代码示例。如果您正苦于以下问题:C++ QXmlSimpleReader::setFeature方法的具体用法?C++ QXmlSimpleReader::setFeature怎么用?C++ QXmlSimpleReader::setFeature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QXmlSimpleReader
的用法示例。
在下文中一共展示了QXmlSimpleReader::setFeature方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fetchtr_ui
void fetchtr_ui( const char *fileName, MetaTranslator *tor,
const char * /* defaultContext */, bool mustExist )
{
QFile f( fileName );
if ( !f.open(IO_ReadOnly) ) {
if ( mustExist )
fprintf( stderr, "lupdate error: cannot open UI file '%s': %s\n",
fileName, strerror(errno) );
return;
}
QTextStream t( &f );
QXmlInputSource in( t );
QXmlSimpleReader reader;
reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE );
reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", TRUE );
reader.setFeature( "http://trolltech.com/xml/features/report-whitespace"
"-only-CharData", FALSE );
QXmlDefaultHandler *hand = new UiHandler( tor, fileName );
reader.setContentHandler( hand );
reader.setErrorHandler( hand );
if ( !reader.parse(in) )
fprintf( stderr, "%s: Parse error in UI file\n", fileName );
reader.setContentHandler( 0 );
reader.setErrorHandler( 0 );
delete hand;
f.close();
}
示例2: source
bool KDReports::Report::loadFromXML( QIODevice* iodevice, ErrorDetails* details )
{
QDomDocument doc;
// Read document from the QIODevice, check for errors
// We need to be able to see the space in <text> </text>, this is why
// we activate the "report-whitespace-only-CharData" feature.
// Unfortunately this leads to lots of whitespace text nodes in between real
// elements in the rest of the document, watch out for that.
if (iodevice->isOpen())
iodevice->reset(); //need to do that to allow consecutive calls of loadFromXML()
QXmlInputSource source( iodevice );
QXmlSimpleReader reader;
reader.setFeature( QLatin1String( "http://xml.org/sax/features/namespaces" ), false );
reader.setFeature( QLatin1String( "http://xml.org/sax/features/namespace-prefixes" ), true );
reader.setFeature( QLatin1String( "http://trolltech.com/xml/features/report-whitespace-only-CharData" ), true );
QString errorMsg;
int errorLine = 0, errorColumn = 0;
bool ret = doc.setContent( &source, &reader, &errorMsg, &errorLine, &errorColumn );
if( !ret ) {
if ( details ) {
details->setLine( errorLine );
details->setColumn( errorColumn );
details->setDriverMessage( errorMsg );
}
else
qWarning( "Malformed XML read in KDReports::Report::loadFromXML(): error message = %s, error line = %d, error column = %d", qPrintable( errorMsg ), errorLine, errorColumn );
return false;
}
return loadFromXML( doc, details );
}
示例3: load
bool MetaTranslator::load( const QString& filename )
{
QFile f( filename );
if ( !f.open(QIODevice::ReadOnly) )
return false;
QXmlInputSource in( &f );
QXmlSimpleReader reader;
reader.setFeature( "http://xml.org/sax/features/namespaces", false );
reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", true );
TsHandler *hand = new TsHandler( this );
reader.setContentHandler( static_cast<QXmlDefaultHandler*>(hand) );
reader.setErrorHandler( static_cast<QXmlDefaultHandler*>(hand) );
bool ok = reader.parse( in );
reader.setContentHandler( 0 );
reader.setErrorHandler( 0 );
m_language = hand->language();
makeFileNamesAbsolute(QFileInfo(filename).absoluteDir());
delete hand;
f.close();
return ok;
}
示例4: loadUI
bool loadUI(Translator &translator, const QString &filename, ConversionData &cd)
{
cd.m_sourceFileName = filename;
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
cd.appendError(QString::fromLatin1("Cannot open %1: %2")
.arg(filename, file.errorString()));
return false;
}
QXmlInputSource in(&file);
QXmlSimpleReader reader;
reader.setFeature(QLatin1String("http://xml.org/sax/features/namespaces"), false);
reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true);
reader.setFeature(QLatin1String(
"http://trolltech.com/xml/features/report-whitespace-only-CharData"), false);
UiReader handler(translator, cd);
reader.setContentHandler(&handler);
reader.setErrorHandler(&handler);
bool result = reader.parse(in);
if (!result)
cd.appendError(QLatin1String("Parse error in UI file"));
reader.setContentHandler(0);
reader.setErrorHandler(0);
return result;
}
示例5: load
bool PhraseBook::load( const QString& filename )
{
QFile f( filename );
if ( !f.open(IO_ReadOnly) )
return FALSE;
QTextStream t( &f );
QXmlInputSource in( t );
QXmlSimpleReader reader;
// don't click on these!
reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE );
reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", TRUE );
reader.setFeature( "http://trolltech.com/xml/features/report-whitespace"
"-only-CharData", FALSE );
QXmlDefaultHandler *hand = new QphHandler( this );
reader.setContentHandler( hand );
reader.setErrorHandler( hand );
bool ok = reader.parse( in );
reader.setContentHandler( 0 );
reader.setErrorHandler( 0 );
delete hand;
f.close();
if ( !ok )
clear();
return ok;
}
示例6: main
int main( int argc, char **argv )
{
QApplication app( argc, argv );
QFile xmlFile( argc == 2 ? argv[1] : "fnord.xml" );
QXmlInputSource source( &xmlFile );
QXmlSimpleReader reader;
QGrid * container = new QGrid( 3 );
QListView * nameSpace = new QListView( container, "table_namespace" );
StructureParser * handler = new StructureParser( nameSpace );
reader.setContentHandler( handler );
reader.parse( source );
QListView * namespacePrefix = new QListView( container,
"table_namespace_prefix" );
handler->setListView( namespacePrefix );
reader.setFeature( "http://xml.org/sax/features/namespace-prefixes",
TRUE );
source.reset();
reader.parse( source );
QListView * prefix = new QListView( container, "table_prefix");
handler->setListView( prefix );
reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE );
source.reset();
reader.parse( source );
// namespace label
(void) new QLabel(
"Default:\n"
"http://xml.org/sax/features/namespaces: TRUE\n"
"http://xml.org/sax/features/namespace-prefixes: FALSE\n",
container );
// namespace prefix label
(void) new QLabel(
"\n"
"http://xml.org/sax/features/namespaces: TRUE\n"
"http://xml.org/sax/features/namespace-prefixes: TRUE\n",
container );
// prefix label
(void) new QLabel(
"\n"
"http://xml.org/sax/features/namespaces: FALSE\n"
"http://xml.org/sax/features/namespace-prefixes: TRUE\n",
container );
app.setMainWidget( container );
container->show();
return app.exec();
}
示例7: load
bool PhraseBook::load(const QString &fileName, bool *langGuessed)
{
QFile f(fileName);
if (!f.open(QIODevice::ReadOnly))
return false;
m_fileName = fileName;
QXmlInputSource in(&f);
QXmlSimpleReader reader;
// don't click on these!
reader.setFeature(QLatin1String("http://xml.org/sax/features/namespaces"), false);
reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true);
reader.setFeature(QLatin1String("http://trolltech.com/xml/features/report-whitespace"
"-only-CharData"), false);
QphHandler *hand = new QphHandler(this);
reader.setContentHandler(hand);
reader.setErrorHandler(hand);
bool ok = reader.parse(in);
reader.setContentHandler(0);
reader.setErrorHandler(0);
Translator::languageAndCountry(hand->language(), &m_language, &m_country);
*langGuessed = false;
if (m_language == QLocale::C) {
QLocale sys;
m_language = sys.language();
m_country = sys.country();
*langGuessed = true;
}
QString lang = hand->sourceLanguage();
if (lang.isEmpty()) {
m_sourceLanguage = QLocale::C;
m_sourceCountry = QLocale::AnyCountry;
} else {
Translator::languageAndCountry(lang, &m_sourceLanguage, &m_sourceCountry);
}
delete hand;
f.close();
if (!ok) {
qDeleteAll(m_phrases);
m_phrases.clear();
} else {
emit listChanged();
}
return ok;
}
示例8: download
void Compiler::download()
{
FileProvider provider;
QString fileName;
if ( provider.get( Settings::self()->wsdlUrl(), fileName, Settings::self()->ignoreSslErrors() ) ) {
QFile file( fileName );
if ( !file.open( QIODevice::ReadOnly ) ) {
qDebug("Unable to download file %s", Settings::self()->wsdlUrl().toEncoded().constData());
provider.cleanUp();
QCoreApplication::exit( 1 );
return;
}
//qDebug() << "parsing" << fileName;
QXmlInputSource source( &file );
QXmlSimpleReader reader;
reader.setFeature( QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true );
QString errorMsg;
int errorLine, errorCol;
QDomDocument doc;
if ( !doc.setContent( &source, &reader, &errorMsg, &errorLine, &errorCol ) ) {
qDebug( "%s at (%d,%d)", qPrintable( errorMsg ), errorLine, errorCol );
QCoreApplication::exit( 2 );
return;
}
parse( doc.documentElement() );
provider.cleanUp();
}
}
示例9: loadAiml
bool AIMLParser::loadAiml(const QString &filename)
{
QDomDocument doc( "mydocument" );
QFile file( filename );
if ( !file.open( IO_ReadOnly ) )
return false;
QXmlInputSource src(&file);
QXmlSimpleReader reader;
reader.setFeature("http://trolltech.com/xml/features/report-whitespace-only-CharData", true);
QString msg;
int line, col;
if ( !doc.setContent( &src, &reader, &msg, &line, &col ) )
{
file.close();
_logStream << QString("Error while parsing %1: %2 (line %3 - col %4)\n").arg(filename).arg(msg).arg(line).arg(col);
return false;
}
file.close();
parseCategories(doc);
return true;
}
示例10: readFile
bool GpxFile::readFile(QString fname, bool pe) {
GpxParser handler(*this);
QFile file( fname );
QXmlInputSource source( &file );
QXmlSimpleReader reader;
reader.setFeature("http://trolltech.com/xml/features/report-whitespace-only-CharData", false);
reader.setContentHandler( &handler );
reader.parse( source );
if (pe) purgeEmptyTracks();
return true;
}
示例11: fetchtr_ui
void fetchtr_ui( const char *fileName, MetaTranslator *tor,
const char * /* defaultContext */, bool mustExist )
{
QFile f( fileName );
if ( !f.open(QIODevice::ReadOnly) ) {
if ( mustExist ) {
#if defined(_MSC_VER) && _MSC_VER >= 1400
char buf[100];
strerror_s(buf, sizeof(buf), errno);
fprintf( stderr, "pylupdate5 error: cannot open UI file '%s': %s\n",
fileName, buf );
#else
fprintf( stderr, "pylupdate5 error: cannot open UI file '%s': %s\n",
fileName, strerror(errno) );
#endif
}
return;
}
QXmlInputSource in( &f );
QXmlSimpleReader reader;
reader.setFeature( "http://xml.org/sax/features/namespaces", false );
reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", true );
reader.setFeature( "http://trolltech.com/xml/features/report-whitespace"
"-only-CharData", false );
QXmlDefaultHandler *hand = new UiHandler( tor, fileName );
reader.setContentHandler( hand );
reader.setErrorHandler( hand );
if ( !reader.parse(in) )
fprintf( stderr, "%s: Parse error in UI file\n", fileName );
reader.setContentHandler( 0 );
reader.setErrorHandler( 0 );
delete hand;
f.close();
}
示例12: asDomDocument
QDomDocument DocumentSource::asDomDocument() const
{
if (!d->parsed)
{
QXmlInputSource source;
source.setData(d->array);
QXmlSimpleReader reader;
reader.setFeature(QLatin1String("http://xml.org/sax/features/namespaces"), true);
if (!d->domDoc.setContent(&source, &reader))
d->domDoc.clear();
d->parsed = true;
}
return d->domDoc;
}
示例13: parse
// currently unused
bool Parser::parse( ParserContext *context, QXmlInputSource *source )
{
QXmlSimpleReader reader;
reader.setFeature( QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true );
QString errorMsg;
int errorLine, errorCol;
QDomDocument doc;
if ( !doc.setContent( source, &reader, &errorMsg, &errorLine, &errorCol ) ) {
qDebug( "%s at (%d,%d)", qPrintable( errorMsg ), errorLine, errorCol );
return false;
}
QDomElement element = doc.documentElement();
const QName name( element.tagName() );
if ( name.localName() != QLatin1String("schema") ) {
qDebug( "document element is '%s'", qPrintable( element.tagName() ) );
return false;
}
return parseSchemaTag( context, element );
}
示例14: load
void XmlSync::load(QString path, quint32 order)
{
QFile structFile(path);
QXmlSimpleReader simpleread;
QXmlInputSource input;
QDomDocument *xmlData;
QDomElement *root;
if(!structFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
fatalExit("Failed to open input file!");
}
if (order == 0) //Input file
{
xmlData = &xmlData_in;
root = &root_in;
}
else //Template file
{
xmlData = &xmlData_out;
root = &root_out;
}
//Use QXmlSimpleReader to read document since the default kills whitespace nodes which are needed.
simpleread.setFeature(QLatin1String("http://trolltech.com/xml/features/report-whitespace-only-CharData"), true);
input.setData(structFile.readAll());
xmlData->setContent(&input, &simpleread);
structFile.close();
// Get root
*root = xmlData->documentElement();
if(root->isNull())
{
fatalExit("Root of the input XML file was not detected!");
}
}
示例15: load
void load( const QString& filename )
{
QFile file( filename );
if ( !file.open( IO_ReadOnly ) )
{
Console::instance()->send( tr( "Unable to open %1!\n" ).arg( filename ) );
return;
}
filenames.push_back( filename );
QXmlInputSource input( &file );
QXmlSimpleReader reader;
reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false );
reader.setContentHandler( this );
reader.setErrorHandler( this );
reader.parse( &input, false );
filenames.pop_back();
}