Convertor wanted: C struct to XML schema

Tan Yiping tanyp at mail.conuco.cn.net
Tue Jul 27 07:09:35 BST 1999


Thanks a lot to Steve, Mike, and John. Your information is very helpful.

However, none of tools you mentioned sovle exactly my problem. My last
message was too short, it seems. OK. Let me post a long one this time.
Hope you are still interested in this topic.

What I want to do basically is to exchange data in XML format between
two
applications over the network. Because XML docs are self-descriptive, it
should be intelligent enough to tolerate some independent interface
upgrading/extension in each of the communication partners. Quite a new
XML application, isn't it?

My current approach is to first define the data to be exchanged in XML
Schema. Then I can parse the XML Schema in (because it's a well-formed
XML doc) and generate XML doc against this schema in DOM objects,
filling
with the data from the a C struct. The point is, when the XML Schema is
parsed in, I have the XML doc structure and variable names in memory.

Let's say I have in memory an instance of data "tNewspaper" of type 
T_Newspaper, defined as following:

typedef int T_BundleParam[6];

typedef struct {
	float	fUSD;		//Price in United States
	float	fDM;		//Price in Germany
}T_Price;

typedef struct {
	char		szName[8];		//Newspaper name
	long		nSubscription;		//Number of Subscription
	T_BundleParam	tBundleParam;		//6 Bundling parameters
	T_Price		tPrice;			//Price
}T_Newspaper;

The XML counterpart of the above definition can be, in IE5-compatible
XML Schema language:

<?xml version="1.0"?>
<Schema xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
	<ElementType name="BundleParam" dt:type="int"/>
	<ElementType name="USD" dt:type="real"/>
	<ElementType name="DM" dt:type="real"/>
	<ElementType name="Name" dt:type="string"/>
	<ElementType name="Subscription" dt:type="int"/>
	<ElementType name="Price" content="eltOnly">
		<element type="USD"/>
		<element type="DM"/>
	</ElementType>
	<ElementType name="Newspaper" content="eltOnly">
		<element type="Name"/>
		<element type="Subscription"/>
		<element type="BundleParam" minOccurs="1"
maxOccurs="*"/>
		<element type="Price"/>
	</ElementType>
</Schema>

(It will be perfect if I can define BundleParam as minOccurs="6"
maxOccurs="6". However, the MSXML parser in IE5 doesn't support so.)

Now I have made the above XML Schema manually. But I have hundreds
of such kind of C structs to be converted. It would be very helpful if
there is
a tool to do the conversion, even if the tool can only translate 80% of
the
syntax correctly!

Is such a tool exist?

Yiping
(Chinese has their given names at last position. There isn't an
international 
standard on name format yet, sorry.)


xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)





More information about the Xml-dev mailing list