小编zlo*_*dan的帖子

使用Qt DOM更新XML文件

我有一个应用程序,它构建一个基于树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)

xml qt dom

7
推荐指数
1
解决办法
7581
查看次数

标签 统计

dom ×1

qt ×1

xml ×1