OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] Genericity and XML-Schema

[ Lists Home | Date Index | Thread Index ]
  • To: <xml-dev@lists.xml.org>
  • Subject: RE: [xml-dev] Genericity and XML-Schema
  • From: "Phil Fuhlman" <pfuhlman@Dexma.com>
  • Date: Fri, 8 Mar 2002 11:33:18 -0600
  • Thread-index: AcHGl14vaklQGoDETleUiehomZmDBAAKZd+Q
  • Thread-topic: [xml-dev] Genericity and XML-Schema

A few moments from the trenches...

I think the answer to your question will be yes, but it may depend on
your opinion of how the "right" syntax might manifest itself.

Ex. Given an XML document fragment something like (indented and CR/LFed
for readability):

<Transaction>
<!-- my Transaction Copyright (c) 2002 Thought You Had A Clue, LLC All
Rights Reserved VersionInfo Major(1) Minor(2) Patch(3) Build (4) -->
	<ShipTo>
		<Address>
			<City>xxx</City>
		</Address>
	</ShipTo>
	<BillTo>
		<Address>
			<City>xxx</City>
		</Address>
	</BillTo>
</Transaction>

If you feel you've got some OO experience but your a schema neophyte
like me you might be tempted to set up a schema that looks something
like (sorry no identation):

<?xml version="1.0" encoding="utf-8"?>
<!-- Context=External -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
<xsd:annotation>
<xsd:documentation xml:lang="en">
Schema for my Transaction Copyright (c) 2002 Thought You Had A Clue, LLC
All Rights Reserved
VersionInfo Major(1) Minor(2) Patch(3) Build(4)
</xsd:documentation>
</xsd:annotation>
<xsd:simpleType name="Address.CityType">
<xsd:annotation>
<xsd:documentation>name of city</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:minLength value="0"/>
<xsd:maxLength value="50"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="AddressClass">
<xsd:all>
<xsd:element name="City" type="Address.CityType" minOccurs="0"
maxOccurs="1" />
</xsd:all>
</xsd:complexType>
<xsd:complexType name="AddressContainer">
<xsd:sequence>
<!-- not used here but included for completeness -->
<xsd:element name="Address" type="AddressClass" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ShipToClass">
<xsd:sequence>
<xsd:element name="Address" type="AddressClass" minOccurs="1"
maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="BillToClass">
<xsd:sequence>
<xsd:element name="Address" type="AddressClass" minOccurs="1"
maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="TransactionClass">
<xsd:all>
<xsd:element name="ShipTo" type="ShipToClass" minOccurs="1"
maxOccurs="1"/>
<xsd:element name="BillTo" type="BillToClass" minOccurs="0"
maxOccurs="1"/>
</xsd:all>
</xsd:complexType>
<xsd:element name="Transaction" type="TransactionClass"/>
</xsd:schema>

This can be expressed quite nicely in "legacy" C++ (a thousand apologies
in advance for not declaring everything with templates and streams and
I'd never do it this way<lol>):

	class Address
	{
	public:
		int SaveAsXML ( std::string &a_sarg );
		int RestoreFromXML ( SomeParserTool &a_spt,
SomeLocalityRef &a_parentnode );

	private:
		std::string m_sCity;
	};

	class Transaction
	{
	public:
		int SaveAsXML ( std::string &a_sarg ) { ...;
m_ShipTo.SaveAsXML(out_stream); m_BillTo.SaveAsXML(out_stream); ...; };
		int RestoreFromXML ( std::string &a_sarg ); /* uses
parser tool */

	private:
		Address m_ShipTo;
		Address m_BillTo;
	};

After assimilating the nuances of schema syntax, one steeped in the
traditions of object oriented design / programming and code reuse (you
might even generate it dynamically from an existing, er, "legacy", data
dictionary) might imagine a schema document like this.

A "generic" XML parser (oh, say like MSXML4) processes these two
documents with no errors.

Caveat(s): there are apparently a number of XML 'authoring tools' out
there today that choke on it because of the reuse of the "AddressClass"
(and might also choke on the period character in the "Address.CityType"
string). Thankfully VI and NOTEPAD are two of them. Both VI and NOTEPAD
can parse both documents with no errors :)

Otherwise it works really rather cool :)

</pff>

-----Original Message-----
From: Andrew Goodchild [mailto:andrewg@dstc.edu.au]
Sent: Friday, March 08, 2002 5:53 AM
To: xml-dev@lists.xml.org
Subject: [xml-dev] Genericity and XML-Schema



Hi,

I know someone has probably asked this question before, but is
genericity/polymorphism supported in XML-Schema?  For example if I have
a
complex type for <list> and want to later on create a list of addressess
or a list of blood pressures.  Is genericity anything more than simply
creating a complex type which extends the <item> in the <list> as an
address or as a blood pressure?

thanks,  Andrew



-----------------------------------------------------------------
The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
initiative of OASIS <http://www.oasis-open.org>

The list archives are at http://lists.xml.org/archives/xml-dev/

To subscribe or unsubscribe from this list use the subscription
manager: <http://lists.xml.org/ob/adm.pl>





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS