当元素声明为nillable时,XmlSchema.read会抛出异常

时间:2009-08-24 16:30:31

标签: xml xsd

我有一个简单的架构,我试图使用XmlSchema.Read()方法读取。我一直在

The 'nillable' attribute is not supported in this context

这是C#中的一个简单代码

XmlSchema schema = null;

using (StreamReader reader = new StreamReader(<Path to Schema file name>)
{
    schema = XmlSchema.Read(reader.BaseStream, null);
}

以下是架构

<xs:schema  xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://xyz.com.schema.bc.mySchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://xyz.com.schema.bc.mySchema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="data">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Component">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="1" maxOccurs="unbounded" name="row">
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element name="changed_by" type="xs:string" nillable="true" />
                                    <xs:element name="column_name" type="xs:string" nillable="true" />
                                    <xs:element name="comment_text" type="xs:string" nillable="true" />
                                    <xs:element name="is_approved" type="xs:string" nillable="true" />
                                    <xs:element name="log_at" type="xs:dateTime" nillable="true" />
                                    <xs:element name="new_val" type="xs:string" nillable="true" />
                                    <xs:element name="old_val" type="xs:string" nillable="true" />
                                    <xs:element name="person_id" type="xs:string" nillable="true" />
                                    <xs:element name="poh_id" type="xs:string" nillable="true" />
                                    <xs:element name="pol_id" type="xs:string" nillable="true" />
                                    <xs:element name="search_name" type="xs:string" nillable="true" />
                                    <xs:element name="unique_id" type="xs:integer" nillable="true" />
                                </xs:sequence>
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
    </xs:complexType>
</xs:element>
</xs:schema>

1 个答案:

答案 0 :(得分:0)

您的架构完全错误。你有一些不匹配的标签。试试这个:

<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://xyz.com.schema.bc.mySchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://xyz.com.schema.bc.mySchema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="data">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Component">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element minOccurs="1" maxOccurs="unbounded" name="row">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="changed_by" type="xs:string" nillable="true"/>
                                        <xs:element name="column_name" type="xs:string" nillable="true"/>
                                        <xs:element name="comment_text" type="xs:string" nillable="true"/>
                                        <xs:element name="is_approved" type="xs:string" nillable="true"/>
                                        <xs:element name="log_at" type="xs:dateTime" nillable="true"/>
                                        <xs:element name="new_val" type="xs:string" nillable="true"/>
                                        <xs:element name="old_val" type="xs:string" nillable="true"/>
                                        <xs:element name="person_id" type="xs:string" nillable="true"/>
                                        <xs:element name="poh_id" type="xs:string" nillable="true"/>
                                        <xs:element name="pol_id" type="xs:string" nillable="true"/>
                                        <xs:element name="search_name" type="xs:string" nillable="true"/>
                                        <xs:element name="unique_id" type="xs:integer" nillable="true"/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>
相关问题