开发者

MiniXML: parsing xml in C

I am parsing an xml file in C using Minixml. I want to get the values "check-time", "check-key" etc from this small eg. file:

<?xml version="1.0"?>
<!--Test-->
<myfile> 
    <command type="start"> 
       <instance>check-time</instance>
       <instance>check-key</instance>
       <instance>check-position</instance>
        <action type="press button">
       <blue>1</blue>
    </action> 
    </command>

</myfile>

Here is my code. I dont know how to extract the data withing the tag. Please help. Why is subnode->next not showing the next instance value?

   fp = fopen( "trial.xml", "r" );
        if(fp == NULL){
            perror("file missing");
        }

        mxml_node_t *tree, *Asset_elem;
        tree =  mxmlLoadFile(NULL, fp,MXML_TEXT_CALLBACK);

        fclose(fp);

        Asset_elem = mxmlWalkNext(tree, tree, MXML_DESCEND_FIRST);

        if(tree != NULL){
        mxml_node_t *node, *subnode, *subsubnode;

            for (node = mxml开发者_JS百科FindElement(Asset_elem, tree,
                                        "command",
                                        "type", "start",
                                        MXML_DESCEND);
                 node != NULL;
                 node = mxmlFindElement(node, Asset_elem,
                         "command",
                         "type", "start",
                                        MXML_DESCEND))
        {

        printf("Inside for loop\n");
            printf("node name= %s\n", node->value.element.name);

            if(node){
                subnode = mxmlFindElement(node, tree, "instance", NULL, NULL, MXML_DESCEND);
                if(subnode != NULL){
                    printf("subnode name= %s\n", subnode->value.element.name);
                    subsubnode = subnode->child;
                    printf("subsubnode name= %s\n", subsubnode->value.text.string);
                    subsubnode = subnode->next;
                    printf("subsubnode name= %s\n", subsubnode->value.text.string);

                }
             }
        }


Now it has don't use subnode, you can try use node->child->value.xxx. Good luck to you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜