2013-04-30 72 views
0

我想描述的XSD这个类的结构,但我无法找到任何解决方案:创建XSD类结构

public class A { 
string property { get; } 
B[] property2 { get; }//occurs 0 to unbound 
} 


public class B { 
string property { get; } 
} 

回答

1

下面是我认为,以下XML架构将帮助您解决您的问题。

<?xml version="1.0" encoding="UTF-8"?> 
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Class" xmlns:tns="http://www.example.org/Class" elementFormDefault="qualified"> 


<element name="A" type="tns:A"></element> 

<simpleType name="property"> 
    <restriction base="string"></restriction> 
</simpleType> 

<complexType name="B"> 
    <sequence> 
     <element name="property" type="tns:property"></element> 
    </sequence> 
</complexType> 

<complexType name="A"> 
    <sequence> 
     <element name="property" type="tns:property"></element> 
     <element name="B" type="tns:B" maxOccurs="unbounded" minOccurs="0"></element> 
    </sequence> 
</complexType> 

1

如果您正在使用C#看看这个提问/回答:

Programatically serialize class to xsd

但是,序列化到XSD时的问题是DataMember属性对XSD有严重限制(请参阅http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/e95ba78b-9932-4d8a-91ac-6b40967d0d8b)。

所以,也许你可以通过序列化生成的XSD并执行一些自定义的修改,主要用于数据的限制(长度,范围,最小值/最大值...)

[编辑]或者,如果你想自己动手看看这http://www.w3schools.com/schema/