Qt 中sax方式 解析 xml文件

前端之家收集整理的这篇文章主要介绍了Qt 中sax方式 解析 xml文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1 bool CSFCfgFileBase::LoadConfigFile( const QString &strCfgFile )
 {
	if( strCfgFile != "" )
	{
		m_strConfigFileName	= strCfgFile;
	}
 
	QFile file(m_strConfigFileName);
	if (!file.open(QFile::ReadOnly | QFile::Text))
	{
		return false;
	}
 
	file.seek( 0 );
 
	QXmlInputSource	xmlInputSource(&file);
 
	QXmlSimpleReader reader;
	reader.setContentHandler(this);
	reader.setErrorHandler(this);
 
	bool bResult = reader.parse( xmlInputSource );
 
	file.close();
 
	if( bResult )
	{
		InitAllFeatures();
		m_bCfgLoaded = true;
	}
 
	return m_bCfgLoaded;
 }
 
2.
bool CSFCfgFileValueExchange::startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts)
{
	if( m_eCurrentRoute == XRT_FEATURE && m_slParseRoute.size() == XRL_FEATURE )
	{
		if( qName == "ValueExchange" )
		{
			m_eCurrentRoute = XRT_FEATURE_VALUEEXCHANGE;
		}
		else
		{
			return CSFCfgFileClass::startElement( namespaceURI, localName, qName, atts );
		}
	}
	else if( m_eCurrentRoute == XRT_FEATURE_VALUEEXCHANGE && m_slParseRoute.size() == XRL_FEATURE_VALUEEXCHANGE )
	{
		if( qName == "ITEM" )
		{
			CSFCfgParserValueExchange::DS_ValueExchangeItem	dsItem;
			CSFCfgParserValueExchange::LoadValueExchangeItem( atts, &dsItem );
			GetCfgValueExchangesPtr()->push_back( dsItem );
		}
		else
		{
		}
	}
	else
	{
		return CSFCfgFileClass::startElement( namespaceURI, atts );
	}
	m_slParseRoute.append( qName );
	return true;
}


3.bool CSFCfgFileValueExchange::endElement(const QString& namespaceURI, const QString& qName)
 {
	if( m_slParseRoute.size() == XRL_FEATURE_VALUEEXCHANGE && m_eCurrentRoute == XRT_FEATURE_VALUEEXCHANGE && qName == "ValueExchange" )
	{
		m_eCurrentRoute = XRT_FEATURE;
	}
	else
	{
		return CSFCfgFileClass::endElement( namespaceURI, qName );
	}
	m_slParseRoute.removeLast();
	return true;
 }

猜你在找的XML相关文章