0

我想用 XSD 来描述这个类结构,但我找不到任何解决方案:

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


public class B {
 string property { get; }
}
4

2 回答 2

1

如果您使用的是 C#,请查看此问题/答案:

以编程方式将类序列化为 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/

于 2013-04-30T16:52:19.400 回答
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>

于 2013-05-02T10:41:12.840 回答