3
想象我有一个递归algebraic data type这样的(Haskell语法):在XML XSD定义递归代数数据类型
data Expr = Zero
| One
| Add Expr Expr
| Mul Expr Expr
我想在XML来表示此,我想对XSD架构它。
我已经找到了如何实现这个语法:
<Expr>
<Add>
<Expr>
<Zero/>
</Expr>
<Expr>
<Mul>
<Expr>
<One/>
</Expr>
<Expr>
<Add>
<Expr>
<One/>
</Expr>
<Expr>
<One/>
</Expr>
</Add>
</Expr>
</Mul>
</Expr>
</Add>
</Expr>
与此架构:
<xs:complexType name="Expr">
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element minOccurs="1" maxOccurs="1" name="Zero" type="Zero" />
<xs:element minOccurs="1" maxOccurs="1" name="One" type="One" />
<xs:element minOccurs="1" maxOccurs="1" name="Add" type="Add" />
<xs:element minOccurs="1" maxOccurs="1" name="Mul" type="Mul" />
</xs:choice>
</xs:complexType>
<xs:complexType name="Zero">
<xs:sequence>
</xs:sequence>
</xs:complexType>
<xs:complexType name="One">
<xs:sequence>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Add">
<xs:sequence>
<xs:element minOccurs="2" maxOccurs="2" name="Expr" type="Expr" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="Mul">
<xs:sequence>
<xs:element minOccurs="2" maxOccurs="2" name="Expr" type="Expr" />
</xs:sequence>
</xs:complexType>
但我真正想要的是这句法:
<Add>
<Zero/>
<Mul>
<One/>
<Add>
<One/>
<One/>
</Add>
</Mul>
</Add>
这是可能?
谢谢!
真棒,感谢您的!我是一个意外的XSD作者,所以我所知道的是我在Intellisense中发现的。 :) – 2010-03-24 20:45:07
现在接下来的问题是,我可以使用替换组与XmlSerializer和继承(和一些属性让它知道我关心的派生类),还是我必须实现IXmlSerializable我自己? – 2010-03-24 20:50:12
回答我自己的问题,是的。此页面非常有用:http://richnewman.wordpress.com/2008/01/28/problems-with-using-xsdexe-to-generate-net-classes-from-the-fpml-xsd-schema-introduction-to - 使用 - FpML的-与净工具部分-4 / – 2010-03-24 21:51:51