mini-XMLライブラリを使用してxmlファイルの作成と解析を実現

3761 ワード

昨日、VxWorksプラットフォームでmini-XMLライブラリを適用してxmlファイルを解析し、どのように使うかを簡単に書きました.
https://blog.csdn.net/jianzhao6205/article/details/81638197
今日は関数マニュアルに基づいてルーチンを書きます.主な機能は、ライブラリ関数を使用してxmlツリーを生成してuserに保存することです.xmlファイル、fopen()関数ファイルパスの書き方(「host:d:\Tornado 2.2\XML\user.xml」)に注意し、生成したファイルを解析して印刷します.簡単なプログラムです
#include
#include
#include
#include
#include"D:\Tornado2.2\XML\xmlTest\src\vxw5\config.h"
#include"D:\Tornado2.2\XML\xmlTest\src\mxml.h"

int vmain()
{
    FILE *fp;
    FILE *fptra;
    mxml_node_t *tree;
    mxml_node_t *xml;    /*  */
    mxml_node_t *data;   /*  */
    mxml_node_t *node;   /*  */
    mxml_node_t *group;  /*  */
    /*              */
    xml = mxmlNewXML("1.0");

    data = mxmlNewElement(xml, "data");

        node = mxmlNewElement(data, "node");
        mxmlElementSetAttrf(node, "id", "0x01");
        mxmlElementSetAttrf(node, "msg", "This is 0x01");

        node = mxmlNewElement(data, "node");
        mxmlElementSetAttrf(node, "id", "0x02");
        mxmlElementSetAttrf(node, "msg", "This is 0x02");

        node = mxmlNewElement(data, "node");
        mxmlElementSetAttrf(node, "id", "0x03");
        mxmlElementSetAttrf(node, "msg", "This is 0x03");

        group = mxmlNewElement(data, "group");

            node = mxmlNewElement(group, "node");
            mxmlElementSetAttrf(node, "id", "0x04");
            mxmlElementSetAttrf(node, "msg", "This is 0x04");

            node = mxmlNewElement(group, "node");
            mxmlElementSetAttrf(node, "id", "0x05");
            mxmlElementSetAttrf(node, "msg", "This is 0x05");

        node = mxmlNewElement(data, "node");
        mxmlElementSetAttrf(node, "id", "0x06");
        mxmlElementSetAttrf(node, "msg", "This is 0x06");

        node = mxmlNewElement(data, "node");
        mxmlElementSetAttrf(node, "id", "0x07");
        mxmlElementSetAttrf(node, "msg", "This is 0x07");
    /*            xml       ,             */
    fp = fopen("host:d:\\Tornado2.2\\XML\\user.xml", "w");
    mxmlSaveFile(xml, fp, MXML_NO_CALLBACK);
    fclose(fp);
    mxmlDelete(xml);
 
    fptra = fopen("host:d:\\Tornado2.2\\XML\\user.xml", "r");
    tree = mxmlLoadFile(NULL, fptra, MXML_TEXT_CALLBACK);
    fclose(fptra);
    /*          ,            */
    for (node = mxmlFindElement(tree, tree, "node", NULL, NULL, MXML_DESCEND);
         node != NULL;
         node = mxmlFindElement(node, tree, "node", NULL, NULL, MXML_DESCEND))
    {
        printf("id = %s, msg = %s 
", mxmlElementGetAttr( node, "id"), mxmlElementGetAttr( node, "msg")); } printf("
"); return 0 ; }

最終生成xmlファイル


    
    
    
    
        
        
    
    
    

使用するリソースはこちらですhttps://download.csdn.net/download/jianzhao6205/10601698  
もし分けられるものがあれば、私は私を信じて、私はあなたに送ることができることを見て、ポイントを稼ぐために、共同で勉強しません