开发者

Inheritance and polymorphism in XSD

开发者 https://www.devze.com 2023-04-03 11:12 出处:网络
My questi开发者_StackOverflow中文版on pretty much repeats this question, which did not receive any answers. Hope I have better luck.

My questi开发者_StackOverflow中文版on pretty much repeats this question, which did not receive any answers. Hope I have better luck.

I'd like to implement inheritance in XSD elements, in a way which supports both polymorphism in the xml, and regular OO inheritance in the classes generated from the XSD.

This is how the C# generated classes should look like (in a simplified example):

class Zoo{ private Animal _animal; }
abstract class Animal{ private int _someProperty; }
class Lion:Animal{ }
class Zebra:Animal{ }

And this is how the Xml should look like

<Zoo> <Lion /> </Zoo>
<Zoo> <Zebra /> </Zoo>

but not:

<Zoo> <Animal /> </Zoo>

I've tried using xs:extension, but it did not work the way I expected. Any thoughts?


developerfusion.co.uk
msdn

The above article uses xsd.exe to go from a class (or class hierarchy) to an xsd schema. Have you tried this and checked if the outcome is acceptable?

I've also added an msdn article on that tool.

And yet another edit: a tool like Enterprise Architect (and similar ones) often has a feature to create an xsd starting from a class diagram (uml). See for example here.

Cheers, Wim

0

精彩评论

暂无评论...
验证码 换一张
取 消