Note that there are some explanatory texts on larger screens.

plurals
  1. POminiXML parsing C API
    primarykey
    data
    text
    <p>I'm trying parse the follow XML file:</p> <pre><code>&lt;root&gt;Root &lt;pai&gt;Pai_1 &lt;filho&gt;Pai1,Filho1&lt;/filho&gt; &lt;filho&gt;Pai1,Filho2&lt;/filho&gt; &lt;/pai&gt; &lt;pai&gt;Pai_2 &lt;filho&gt;Pai2,Filho1&lt;/filho&gt; &lt;filho&gt;Pai2,Filho2&lt;/filho&gt; &lt;/pai&gt; &lt;/root&gt; </code></pre> <p>I'm using the follow C code:</p> <pre><code>//... open file xml_tree = mxmlLoadFile(NULL, fp, MXML_TEXT_CALLBACK); node = xml_tree; printf("%s\n", mxmlGetText(node, NULL)); // here the return is: Root // I expected: Root, OK node = xml_tree-&gt;child; printf("%s\n", mxmlGetText(node, NULL)); // here the return is: Root // I expected: Pai_1, not OK node = mxmlGetFirstChild(xml_tree); printf("%s\n", mxmlGetText(node, NULL)); // here the return is: Root // I expected: Pai_1, not OK node = mxmlFindElement(xml_tree, xml_tree, "pai", NULL, NULL, MXML_DESCEND); printf("%s\n", mxmlGetText(node, NULL)); // here the return is: Pai_1 // I expected: Pai_1, OK node = mxmlGetNextSibling(node); printf("%s\n", mxmlGetText(node, NULL)); // here the return is: (NULL) // I expected: Pai_2, not OK </code></pre> <p>How can I access the child of the root? Where my concept of access is wrong?</p> <p>Thank you.</p> <hr> <p>EDIT after @RutgersMike response</p> <p>I expand your while loop to try understand the concept of minixml:</p> <pre><code>root = mxmlLoadFile(NULL,fp,MXML_TEXT_CALLBACK); node = root; printf("------- Root\n"); fprintf(stdout,"Element = %s\n",mxmlGetElement(node)); fprintf(stdout," Value = %s\n",mxmlGetText(node,0)); printf("\n"); printf("------- First child of Root\n"); node = mxmlGetFirstChild(node); fprintf(stdout,"Element = %s\n",mxmlGetElement(node)); fprintf(stdout," Value = %s\n",mxmlGetText(node,0)); printf("\n"); printf("------- Sibling 1 of First child of Root\n"); node = mxmlGetNextSibling(node); fprintf(stdout,"Element = %s\n",mxmlGetElement(node)); fprintf(stdout," Value = %s\n",mxmlGetText(node,0)); printf("\n"); printf("------- Sibling 2 of First child of Root\n"); node = mxmlGetNextSibling(node); fprintf(stdout,"Element = %s\n",mxmlGetElement(node)); fprintf(stdout," Value = %s\n",mxmlGetText(node,0)); printf("\n"); printf("------- Sibling 3 of First child of Root\n"); node = mxmlGetNextSibling(node); fprintf(stdout,"Element = %s\n",mxmlGetElement(node)); fprintf(stdout," Value = %s\n",mxmlGetText(node,0)); printf("\n"); printf("------- Sibling 4 of First child of Root\n"); node = mxmlGetNextSibling(node); fprintf(stdout,"Element = %s\n",mxmlGetElement(node)); fprintf(stdout," Value = %s\n",mxmlGetText(node,0)); printf("\n"); </code></pre> <p>The result this was:</p> <pre><code>------- Root Element = root Value = Root ------- First child of Root Element = (null) Value = Root ------- Sibling 1 of First child of Root Element = (null) Value = ------- Sibling 2 of First child of Root Element = pai Value = Pai_1 ------- Sibling 3 of First child of Root Element = (null) Value = ------- Sibling 4 of First child of Root Element = pai Value = Pai_2 </code></pre> <p>I think this concept of navigation between child and parent a little strange. Why there are (null) values between sibling?</p> <p>I am considering go back to ezxml.</p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload