相关疑难解决方法(0)

如何以编程方式从类型生成xml架构?

我正在尝试以编程方式从任何.net类型生成xs:schema.我知道我可以使用反射并通过迭代公共属性来生成它,但是有内置的方法吗?

例:

[Serializable]
public class Person
{
    [XmlElement(IsNullable = false)] public string FirstName { get; set; }
    [XmlElement(IsNullable = false)] public string LastName { get; set; }
    [XmlElement(IsNullable = true)] public string PhoneNo { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

期望的输出:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Person" type="Person" />
  <xs:complexType name="Person">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="FirstName" type="xs:string" />
      <xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="LastName" type="xs:string" />
      <xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="PhoneNo" type="xs:string" />
    </xs:sequence>
  </xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)

.net c# xml

12
推荐指数
3
解决办法
2万
查看次数

标签 统计

.net ×1

c# ×1

xml ×1