如何使用 C# 解析 XSD 文件

How to parse XSD file using c#

我想阅读 XSD 文件。但无法找到解析 XSD 文件的正确方法。

<xsd:group name="group_name">
    <xsd:annotation>
        <xsd:documentation>Some text is here</xsd:documentation>
    </xsd:annotation>
    <xsd:sequence>
        <xsd:element minOccurs="0" name="Element_1" type="string">
            <xsd:annotation>
                <xsd:documentation>Some text is here</xsd:documentation>
            </xsd:annotation>
        </xsd:element>
        <xsd:element minOccurs="0" name="Element_2" type="string">
            <xsd:annotation>
                <xsd:documentation>Some text is here</xsd:documentation>
            </xsd:annotation>
        </xsd:element>
    </xsd:sequence>
</xsd:group>

我想读取文件中的每个组,该组中的一个序列和该序列中的元素。而且还需要看各组的注解,我可以元素。

我该怎么做?

XSD 文件是 XML 文件,因此您可以使用 XML 解析器读取 ot,例如 LINQ,它是从数据源读取数据的查询,link 波纹管是一个很好的来源: https://msdn.microsoft.com/en-us/library/bb397933.aspx 因此,第一步是加载 xml 文件,然后通过 LINQ 查询

读取它