LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

retrieving values from XML child elements

I have the following simple XML code and I am trying to retrieve the values from the child elements C1 and C2 and put it in a buffer to use later on. However I always get an error... Can someboby point out what I am missing?
 
Thanks.
 
(My xml code)
<?xml version="1.0" encoding="ISO-8859-1"?>
<Test>
 <C1>1000</C1>
 <C2>2000</C2>
</Test>
 
(My LabWin code)
 
void getChannelValues()
{
 
 char ch1[25], ch2 [25] = NULL;
 CVIXMLStatus status;
 CVIXMLElement C1 = 0, C2 = 0;
 CVIXMLDocument test1;
 status = CVIXMLLoadDocument ("C:\\Temp\\test.xml", &test1);
 status = CVIXMLGetElementValue (C1, ch1);
 CVIXMLDiscardElement (C1);
 CVIXMLDiscardDocument (test1);
 status = CVIXMLLoadDocument ("C:\\Temp\\test.xml", &test1);
 CVIXMLGetElementValue (C2, ch2);
 CVIXMLDiscardElement (C2);
 CVIXMLDiscardDocument (test1);
  
}
0 Kudos
Message 1 of 4
(3,884 Views)
Try this code:

#include <cvirte.h>
#include "CviXml.h"

char ch1[25]="", ch2 [25]="";
CVIXMLStatus status;
CVIXMLElement RootElement;
CVIXMLElement C;
CVIXMLDocument test1;
 
int main (int argc, char *argv[])
{
    if (InitCVIRTE (0, argv, 0) == 0)
        return -1;    /* out of memory */
 
 
 status = CVIXMLLoadDocument ("test.xml", &test1);
 
 status = CVIXMLGetRootElement (test1, &RootElement);//<Test>
 
 //Get C1 tag value
 status = CVIXMLGetChildElementByTag (RootElement, "C1", &C); //"<C1>"
 //status = CVIXMLGetElementValueLength (C, &len);
 status = CVIXMLGetElementValue (C, ch1);
 CVIXMLDiscardElement (C);
 
 //Get C2 tag value
 status = CVIXMLGetChildElementByTag (RootElement, "C2", &C);//<C2>
 //status = CVIXMLGetElementValueLength (C, &len);
 status = CVIXMLGetElementValue (C, ch2);
 CVIXMLDiscardElement (C);
 
 CVIXMLDiscardElement (RootElement);
 CVIXMLDiscardDocument (test1);
    
    return 0;
}
0 Kudos
Message 2 of 4
(3,870 Views)
Howdy qsa301,

I would also like to add to refer to our LabWindows/CVI XML shipping examples (Help >> Find Examples; type "XML" in the Index tab) that demonstrate using several XML functions. These examples should also give you some more insight.

Hope this helps!
Jonathan N.
National Instruments
0 Kudos
Message 3 of 4
(3,857 Views)
Thank you all for your help
0 Kudos
Message 4 of 4
(3,837 Views)