I have some questions about using gSOAP for parsing the XML. If anyone has been experienced with this, please give me some helps. Thanks :D
I never know about XML before, and now I need to parse the XML to the structs in C. Then I found some recommendation to use gSOAP data binding. And yes! it helps me to generate a header file contains of structs from an XSD (XML Schema). But now, I don't know what to do with the struct or the XML file either. I need to put the XML data into the struct automatically (I mean, if the XSD change, the code shouldn't have to be changed also). Is there anything I don't know about gSOAP related to my problem? Or I have to code myself to put in the data? Thank you for your concern and time.
Cheers!
----Addition----
This is what I have done, I worked in Terminal in Linux : I have an XSD file named try.xsd
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name='Root'>
<xs:complexType>
<xs:sequence>
<xs:element name='Customers'>
<xs:complexType>
<xs:sequence>
<xs:element name='Customer' type='xs:string' minOccurs='0' maxOccurs='unbounded' />
<xs:element name='Order' type='xs:string' minOccurs='0' maxOccurs='unbounded' />
</xs:sequence>
<xs:attribute name='customerid' use='required' type='xs:integer'/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Then I use gSOAP with this XSD file :
I generated the try.h file with the wsdl2h by
wsdl2h -c -a -o try.h -t typemap.dat try.xsd
Then I generated the rest files : ns1.nsmap, soapC.c soapH.H soapClient.c soapServer.c soapStub.h by
soapcpp2 -c -t -L -I "/home/celia/Documents/gsoap-2.7/gsoap/import" try.h
Then make the .c file and included the soapH.h and ns1.nsmap. Also include in your folder the stdsoap2.h and stdsoap2.c (you can find them in the gSOAP package).
In the file soapStub.h, the struct is built :
....
struct _ns1__Root_Customers
{
int __sizeCustomer; /* sequence of elements <Customer> */
char **Customer; /* optional element of type xsd:string */
int __sizeOrder; /* sequence of elements <Order> */
char **Order; /* optional element of type xsd:string */
char *customerid; /* required attribute of type xsd:integer */
}
struct _ns1__Root
{
struct _ns1__Root_Customers Customers; /* required element of type ssrf1:Akar-Customers */
}
....
So now, I'm confused how to code that make the XML data automatically go to this struct without manually "Customers->customerid = node->children->content". So, if the XSD change, I don't have to change the code also.