LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Does CVIXMLFindElements puts the elements in the ListType in a strange order ?

Dear all,

I am using CVI 8.0.1 with the cvixml.fp 'xml-driver'/parser. When I retrieve a list of elements using: CVIXMLFindElements,
I get the 'feeling' that the elements are placed in the ListType in a strange order.
My code pretty much looks like this:

#define FILE_PATH "test2.xml"
void xmlTest2(){
    CVIXMLDocument    cfgDoc = 0;
    CVIXMLElement     currElem = 0,child=0;
   
    ListType elementList = 0;
    char valueBuffer[10];
    int numberOfElements,cntr;
 
    //load the doc
    CVIXMLLoadDocument (FILE_PATH, &cfgDoc);
   
    //get the root
    CVIXMLGetRootElement (cfgDoc, &currElem);
   
    //get the childeren we want
    CVIXMLFindElements (currElem,"a",&elementList);
   
    //get the number of elements
    numberOfElements = ListNumItems (elementList);

    //go through all elements
    for(cntr=0;cntr<numberOfElements;cntr++){
        //get next element
        ListGetItem (elementList, &child, cntr);
        //get the value of the element       
        CVIXMLGetElementValue(child,valueBuffer);   
        //print fvalue
        printf("%s\n",valueBuffer);
    }

    //don't bother memory clean-up for now, or is that the problem ?
}

the xml file looks like this:
<?xml version="1.0"?>
<root>
    <a>1</a>
    <a>2</a>
    <a>3</a>
    <a>4</a>
    <a>5</a>
</root>   

The print out is like this:
5
1
2
3
4

Any thoughts ? Thanks in advance !

0 Kudos
Message 1 of 3
(3,418 Views)

The ListType indexing is 1-based. Your for statement should be:

for(cntr=1;cntr<=numberOfElements;cntr++){

...

}

0 Kudos
Message 2 of 3
(3,403 Views)
Thank you so much !
That was a stupid of me Smiley Happy
0 Kudos
Message 3 of 3
(3,389 Views)