Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / October 2004

Tip: Looking for answers? Try searching our database.

Polymorphism in XSD

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Jansen - 27 Oct 2004 22:12 GMT
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)
Maksim - 27 Oct 2004 23:27 GMT
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>

> I'm trying to mirror some classes in an XML Schema:
>
[quoted text clipped - 22 lines]
> Mike Jansen
> (mjansen)(at)(primepro-com)
Mike Jansen - 28 Oct 2004 18:39 GMT
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

> Just a quick sketch ( could be done better) but you will see a possible way.
>
[quoted text clipped - 63 lines]
> > Mike Jansen
> > (mjansen)(at)(primepro-com)
Maksim - 28 Oct 2004 19:35 GMT
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

> Maksim,
>
[quoted text clipped - 84 lines]
> > > Mike Jansen
> > > (mjansen)(at)(primepro-com)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.