473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Polymorphism in XSD

I'm trying to mirror some classes in an XML Schema:

abstract class EndPoint
class FileEndPoint: EndPoint
class FtpEndPoint: EndPoint

How can I mirror these in XML such that:

<EndPoint> could contain either ...
<EndPoint type="file" folder="..."/>
or
<EndPoint type="ftp" site="site.com" port="21" .../>

....depending on whether or not it was a FileEndPoint or FtpEndPoint. I have
seen mention of "equivalence", but have not been able to track anything
specific down. substitutionGroup doesn't give me what I want because the
app has to know different element names. "extension" doesn't seem to quite
do it either because you are still renaming an element. I'd like all the
attributes for the class -- whether from the base or derived class -- to be
in the same element.

Appreciate any help.

Thanks,
Mike Jansen
(mjansen)(at)(primepro-com)
Nov 12 '05 #1
3 3133
Just a quick sketch ( could be done better) but you will see a possible way.

<xs:complexType name="EndPoint_t" abstract="1" />

<xs:complexType name="FileEndPoint_t">
<xs:complexContent>
<xs:extension base="EndPoint_t">
<xs:attribute name="folder" use="required" type="xs:anyURI" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="FtpEndPoint_t">
<xs:complexContent>
<xs:extension base="EndPoint_t">
<xs:attribute name="site" use="required" type="xs:anyURI" />
<xs:attribute name="port" use="required" type="xs:int" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

<!-- choise #1 -->
<!-- will require something like
<EndPoint folder="..." xsi:type="file_t"/>
-->
<xs:element name="EndPoint" type="EndPoint_t" />

<!-- choise #2 -->
<!-- will look like
<EndPoints>
<file folder="..." />
-->
<xs:element name="EndPoints">
<xs:complexType>
<xs:choice>
<xs:element name="file" type="FileEndPoint_t" />
<xs:element name="ftp" type="FtpEndPoint_t" />
</xs:choice>
</xs:complexType>
</xs:element>
"Mike Jansen" wrote:
I'm trying to mirror some classes in an XML Schema:

abstract class EndPoint
class FileEndPoint: EndPoint
class FtpEndPoint: EndPoint

How can I mirror these in XML such that:

<EndPoint> could contain either ...
<EndPoint type="file" folder="..."/>
or
<EndPoint type="ftp" site="site.com" port="21" .../>

....depending on whether or not it was a FileEndPoint or FtpEndPoint. I have
seen mention of "equivalence", but have not been able to track anything
specific down. substitutionGroup doesn't give me what I want because the
app has to know different element names. "extension" doesn't seem to quite
do it either because you are still renaming an element. I'd like all the
attributes for the class -- whether from the base or derived class -- to be
in the same element.

Appreciate any help.

Thanks,
Mike Jansen
(mjansen)(at)(primepro-com)

Nov 12 '05 #2
Maksim,

Thanks. I had tried the <xs:choice> and its currently the one I'm going
with.

I liked better your other option where you use <xs:extension>, create the
element with the type of the base class, and then in the instance use
xsi:type, but I couldn't get that to validate properly in Visual Studio.NET.
(It seems VS.NET doesn't handle the xs:extension that great in the XML
editor, as far as validation and intellisense).

Thanks for your input and any further thoughts.

Mike

"Maksim" <Ma****@discussions.microsoft.com> wrote in message
news:8B**********************************@microsof t.com...
Just a quick sketch ( could be done better) but you will see a possible way.
<xs:complexType name="EndPoint_t" abstract="1" />

<xs:complexType name="FileEndPoint_t">
<xs:complexContent>
<xs:extension base="EndPoint_t">
<xs:attribute name="folder" use="required" type="xs:anyURI" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="FtpEndPoint_t">
<xs:complexContent>
<xs:extension base="EndPoint_t">
<xs:attribute name="site" use="required" type="xs:anyURI" />
<xs:attribute name="port" use="required" type="xs:int" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

<!-- choise #1 -->
<!-- will require something like
<EndPoint folder="..." xsi:type="file_t"/>
-->
<xs:element name="EndPoint" type="EndPoint_t" />

<!-- choise #2 -->
<!-- will look like
<EndPoints>
<file folder="..." />
-->
<xs:element name="EndPoints">
<xs:complexType>
<xs:choice>
<xs:element name="file" type="FileEndPoint_t" />
<xs:element name="ftp" type="FtpEndPoint_t" />
</xs:choice>
</xs:complexType>
</xs:element>
"Mike Jansen" wrote:
I'm trying to mirror some classes in an XML Schema:

abstract class EndPoint
class FileEndPoint: EndPoint
class FtpEndPoint: EndPoint

How can I mirror these in XML such that:

<EndPoint> could contain either ...
<EndPoint type="file" folder="..."/>
or
<EndPoint type="ftp" site="site.com" port="21" .../>

....depending on whether or not it was a FileEndPoint or FtpEndPoint. I have seen mention of "equivalence", but have not been able to track anything
specific down. substitutionGroup doesn't give me what I want because the app has to know different element names. "extension" doesn't seem to quite do it either because you are still renaming an element. I'd like all the attributes for the class -- whether from the base or derived class -- to be in the same element.

Appreciate any help.

Thanks,
Mike Jansen
(mjansen)(at)(primepro-com)

Nov 12 '05 #3
In case if you do not know that:

here is a little trick you could use. Put your schema into the
"<VISUAL STUDIO ROOT>\Common7\Packages\schemas\xml" folder.

Then you can create corresponding xml and that "popup helper" (IntelliSense)
will offer you to choose a namespace
as soon as you type "xmlns=", then you can validate you your xml.

Here is a link to W3C document that talks about abstract types

http://www.w3.org/TR/xmlschema-0/#abstract

Regards

"Mike Jansen" wrote:
Maksim,

Thanks. I had tried the <xs:choice> and its currently the one I'm going
with.

I liked better your other option where you use <xs:extension>, create the
element with the type of the base class, and then in the instance use
xsi:type, but I couldn't get that to validate properly in Visual Studio.NET.
(It seems VS.NET doesn't handle the xs:extension that great in the XML
editor, as far as validation and intellisense).

Thanks for your input and any further thoughts.

Mike

"Maksim" <Ma****@discussions.microsoft.com> wrote in message
news:8B**********************************@microsof t.com...
Just a quick sketch ( could be done better) but you will see a possible

way.

<xs:complexType name="EndPoint_t" abstract="1" />

<xs:complexType name="FileEndPoint_t">
<xs:complexContent>
<xs:extension base="EndPoint_t">
<xs:attribute name="folder" use="required" type="xs:anyURI" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="FtpEndPoint_t">
<xs:complexContent>
<xs:extension base="EndPoint_t">
<xs:attribute name="site" use="required" type="xs:anyURI" />
<xs:attribute name="port" use="required" type="xs:int" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

<!-- choise #1 -->
<!-- will require something like
<EndPoint folder="..." xsi:type="file_t"/>
-->
<xs:element name="EndPoint" type="EndPoint_t" />

<!-- choise #2 -->
<!-- will look like
<EndPoints>
<file folder="..." />
-->
<xs:element name="EndPoints">
<xs:complexType>
<xs:choice>
<xs:element name="file" type="FileEndPoint_t" />
<xs:element name="ftp" type="FtpEndPoint_t" />
</xs:choice>
</xs:complexType>
</xs:element>
"Mike Jansen" wrote:
I'm trying to mirror some classes in an XML Schema:

abstract class EndPoint
class FileEndPoint: EndPoint
class FtpEndPoint: EndPoint

How can I mirror these in XML such that:

<EndPoint> could contain either ...
<EndPoint type="file" folder="..."/>
or
<EndPoint type="ftp" site="site.com" port="21" .../>

....depending on whether or not it was a FileEndPoint or FtpEndPoint. I have seen mention of "equivalence", but have not been able to track anything
specific down. substitutionGroup doesn't give me what I want because the app has to know different element names. "extension" doesn't seem to quite do it either because you are still renaming an element. I'd like all the attributes for the class -- whether from the base or derived class -- to be in the same element.

Appreciate any help.

Thanks,
Mike Jansen
(mjansen)(at)(primepro-com)


Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Mike Meng | last post by:
hi all, I'm a newbie Python programmer with a C++ brain inside. I have a lightweight framework in which I design a base class and expect user to extend. In other part of the framework, I heavily...
18
by: Ken | last post by:
Hi. Can anyone refer me to any articles about the compatibility between c++ polymorphism and real-time programming? I'm currently on a real-time c++ project, and we're having a discussion...
3
by: E. Robert Tisdale | last post by:
polymorph just means "many form(s)". The definition in plain English http://www.bartleby.com/61/66/P0426600.html and narrower definitions in the context of computer programming ...
11
by: richard pickworth | last post by:
Can anyone explain polymorphism?(very simply). thanks richard
4
by: LP | last post by:
Hi, I understand the concept/definition of polymorphism. But what does the term "runtime polymorphism" mean? I was asked to define it during a technical interview. I gave a guy vanilla definition...
13
by: Krivenok Dmitry | last post by:
Hello all! Perhaps the most important feature of dynamic polymorphism is ability to handle heterogeneous collections of objects. ("C++ Templates: The Complete Guide" by David Vandevoorde and...
18
by: Seigfried | last post by:
I have to write a paper about object oriented programming and I'm doing some reading to make sure I understand it. In a book I'm reading, however, polymorphism is defined as: "the ability of two...
2
by: sarathy | last post by:
Hi all, I need a small clarification reg. Templates and Polymorphism. I believe templates is really a good feature, which can be used to implement generic functions and classes. But i doubt...
11
by: chsalvia | last post by:
I've been programming in C++ for a little over 2 years, and I still find myself wondering when I should use polymorphism. Some people claim that polymorphism is such an integral part of C++,...
17
by: Bart Friederichs | last post by:
Hello, I created the following inheritance: class Parent { public: void foo(int i); }; class Child : public Parent {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.