我有一个应用程序,它构建一个基于树Qt组件的左侧菜单.为了加载它,我需要解析XML文件.XML文件如下所示:
<comandos>
<categoria>
<nome>Cupom fiscal</nome>
<comando>
<nome>01 - Abrir Cupom Fiscal</nome>
<env>3</env>
<rec>4</rec>
<desc>CNPJ / CPF : </desc>
<desc>Nome : </desc>
<desc>Endereco: </desc>
</comando>
</categoria>
</comandos>
Run Code Online (Sandbox Code Playgroud)
我实际上可以使用QtDOM读取这个XML.
QDomDocument doc( "ComandosML" );
QFile file( "comandos.xml" );
int r = 0;
datafields.clear();
receFields.clear();
categories.clear();
if( !file.open( QIODevice::ReadOnly ) )
return -1;
if( !doc.setContent( &file ) )
{
file.close();
return -2;
}
// Ok we are ready to parse DOM
QDomElement root = doc.documentElement();
if( root.tagName() != "comandos" )
return -3;
QDomNode n …Run Code Online (Sandbox Code Playgroud)