summaryrefslogtreecommitdiffstats
path: root/examples/xsd2c/ex4
diff options
context:
space:
mode:
Diffstat (limited to 'examples/xsd2c/ex4')
-rw-r--r--examples/xsd2c/ex4/Makefile38
-rw-r--r--examples/xsd2c/ex4/README37
-rw-r--r--examples/xsd2c/ex4/ex4.c94
-rwxr-xr-xexamples/xsd2c/ex4/ex4.xml7
-rw-r--r--examples/xsd2c/ex4/ex4.xsd13
5 files changed, 189 insertions, 0 deletions
diff --git a/examples/xsd2c/ex4/Makefile b/examples/xsd2c/ex4/Makefile
new file mode 100644
index 0000000..966a61d
--- /dev/null
+++ b/examples/xsd2c/ex4/Makefile
@@ -0,0 +1,38 @@
+#########################################################
+#
+# XSD2C Examles Makefile
+#
+#########################################################
+
+SHELL = bash
+CC = gcc
+
+
+VPATH = . ../
+
+EXECNAME= ex4.exe
+XSDFILE = ex4.xsd
+EXSRC = ex4.c utils.c
+GENSRC = Person_xsd.c
+
+EXOBJ = $(addsuffix .o, $(basename $(EXSRC)))
+GENOBJ = $(addsuffix .o, $(basename $(GENSRC)))
+OBJECTS = $(EXOBJ) $(GENOBJ)
+XSD2C = ../../xsd2c
+
+CFLAGS = `xml2-config --cflags`
+CLIBS = `xml2-config --libs`
+
+$(EXECNAME): stubs $(GENSRC) $(OBJECTS)
+ $(CC) -g $(CFLAGS) -o $@ $(OBJECTS) $(CLIBS)
+
+
+stubs:
+ $(XSD2C) -S $(XSDFILE)
+
+clean:
+ -@rm -f *.o
+ -@rm -f *_xsd.h
+ -@rm -f *_xsd.c
+ -@rm -f *~
+ -@rm -f $(EXECNAME)
diff --git a/examples/xsd2c/ex4/README b/examples/xsd2c/ex4/README
new file mode 100644
index 0000000..3303af9
--- /dev/null
+++ b/examples/xsd2c/ex4/README
@@ -0,0 +1,37 @@
+##################################################
+#
+# PROJECT: xsd2c examples
+# CREATED: 27.05.2004
+# WRITTEN BY: Ferhat Ayaz
+#
+##################################################
+
+
+DESCRIPTION:
+
+ This example uses a simple comlexType (Person)
+ to show you how to:
+
+ + deserialize
+
+ a xsd object in c
+
+
+FILES:
+
+ ex4.c : Main program code
+ ex4.xsd : XML Schema
+ Makefile : The makefile
+ README : This file
+
+
+ After you make the program with
+
+ $>make
+
+ the following c files will be generated:
+
+ + Person_xsd.h
+ + Person_xsd.c
+
+
diff --git a/examples/xsd2c/ex4/ex4.c b/examples/xsd2c/ex4/ex4.c
new file mode 100644
index 0000000..aa2c1ef
--- /dev/null
+++ b/examples/xsd2c/ex4/ex4.c
@@ -0,0 +1,94 @@
+/******************************************************************
+ * $Id: ex4.c,v 1.1 2004/06/02 11:20:50 snowdrop Exp $
+ *
+ * CSOAP Project: A SOAP client/server library in C
+ * Copyright (C) 2003 Ferhat Ayaz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Email: ayaz@jprogrammet.net
+ ******************************************************************/
+
+/* This header will be generated by xsd2c */
+#include "Person_xsd.h"
+
+ /* For stdout writers */
+#include "../utils.h"
+
+#include <libxml/parser.h>
+
+
+struct Person* LoadFromFile(const char* filename)
+{
+ struct Person* person; /* object created by xsd2c */
+
+ xmlDocPtr doc;
+ xmlNodePtr cur;
+
+ doc = xmlParseFile(filename);
+
+ if (doc == NULL ) {
+ fprintf(stderr,"Document not parsed successfully. \n");
+ return NULL;
+ }
+
+ cur = xmlDocGetRootElement(doc);
+
+ if (cur == NULL) {
+ fprintf(stderr,"empty document\n");
+ xmlFreeDoc(doc);
+ return NULL;
+ }
+
+ printf("Deserialize ...\n");
+ person = Person_Deserialize(cur);
+ printf("Deserialize complete\n");
+
+ xmlFreeDoc(doc);
+
+ return person;
+}
+
+int main(int argc, char *argv[])
+{
+ struct Person* person; /* object created by xsd2c */
+
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s <xml file>\n", argv[0]);
+ return 1;
+ }
+
+ person = LoadFromFile(argv[1]);
+
+ if (person == NULL) {
+ fprintf(stderr, "Can not deserialize Person\n");
+ return 1;
+ }
+
+ /* Serialize the Person object. (Just for test)
+ The 3 sax callback functions
+ will just print the data to stdout
+ */
+ Person_Sax_Serialize(person, "Employee",
+ Writer_StartElement,
+ Writer_Characters,
+ Writer_EndElement, 0);
+
+ /* Free the Person */
+ Person_Free(person);
+
+ return 0;
+}
diff --git a/examples/xsd2c/ex4/ex4.xml b/examples/xsd2c/ex4/ex4.xml
new file mode 100755
index 0000000..ebe4283
--- /dev/null
+++ b/examples/xsd2c/ex4/ex4.xml
@@ -0,0 +1,7 @@
+<Employee id = "id0001">
+ <Name>John</Name>
+ <Lastname>Smith</Lastname>
+ <Degree>34</Degree>
+ <Project>csoap</Project>
+ <Project>xsd2c</Project>
+</Employee>
diff --git a/examples/xsd2c/ex4/ex4.xsd b/examples/xsd2c/ex4/ex4.xsd
new file mode 100644
index 0000000..42ab46f
--- /dev/null
+++ b/examples/xsd2c/ex4/ex4.xsd
@@ -0,0 +1,13 @@
+<schema>
+
+ <complexType name="Person">
+ <attribute name="id" type="xs:string"/>
+ <sequence>
+ <element name="Name" type="xs:string"/>
+ <element name="Lastname" type="xs:string"/>
+ <element name="Degree" type="xs:int"/>
+ <element name="Project" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ </complexType>
+
+</schema>