Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This XML is to parsed through the Libxml in C.

XML
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfPDSCustomerinfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
  <PDSCustomerinfo>
    <Resp>000</Resp>
  </PDSCustomerinfo>
  <PDSCustomerinfo>
    <CommodityId>1</CommodityId>
    <CommodityName>SUGAR</CommodityName>
    <CommodityDetails>Normal,1100,2000,28-01-2013,27-02-2013,Special,200,1000,28-01-2013,28-01-2013</CommodityDetails>
  </PDSCustomerinfo>
  <PDSCustomerinfo>
    <CommodityId>2</CommodityId>
    <CommodityName>WHEAT</CommodityName>
    <CommodityDetails>Normal,200,1000,28-01-2013,27-02-2013</CommodityDetails>
  </PDSCustomerinfo>
  <PDSCustomerinfo>
    <CommodityId>3</CommodityId>
    <CommodityName>PULSES</CommodityName>
    <CommodityDetails>Normal,300,1000,28-01-2013,27-02-2013</CommodityDetails>
  </PDSCustomerinfo>
  <PDSCustomerinfo>
    <CommodityId>4</CommodityId>
    <CommodityName>RICE</CommodityName>
    <CommodityDetails>Normal,400,1000,28-01-2013,27-02-2013</CommodityDetails>
  </PDSCustomerinfo>
</ArrayOfPDSCustomerinfo>


This is the function by which I am trying to parse this XML.


Function:
C++
static void custXmlParse(xmlNode * a_node)
{
    xmlNode *cur_node = NULL;
        xmlChar *value = NULL;

        for (cur_node = a_node; cur_node; cur_node = cur_node->next)
    {
            if (cur_node->type == XML_ELEMENT_NODE)
        {
            if(strcmp(cur_node->name,"Resp")==0)
            {
                value = xmlNodeGetContent(cur_node);
                printf("%s\n", value);
            }
            }
            agentXmlParse(cur_node->children);
        }
}


here in the output the node 'CommodityDetails' value is missing. I had google a lot for the solution but I am not founding teh solution. Please help me to sort out this mess. Thanks in advance.
Posted
Updated 13-May-13 1:46am
v6
Comments
E.F. Nijboer 13-May-13 8:08am    
What is the output you get?
Richard MacCutchan 13-May-13 8:59am    
The only time you print any output is when the nodename is "Resp", and there is only one such node in your XML that I can see.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900