0

我有一个看起来像这样的 XML

<?xml version="1.0" encoding="UTF-8"?>
<!-- FCT Automated Data Transfer Configuration -->
<config_info>
  <!--First Server -->
  <transfer_configuration ID="1">
    <target_info>
      <connection_string>Data Source=xyz;Initial Catalog=abc; User id=123; Password=Welcome1;</connection_string>
      <table_name>t1234</table_name>
    </target_info>
    <source_info>
      <access_file_path>Provider= Microsoft Office 12.0 Access Database Engine OLE DB Provider ; Data Source=C:\Data\Data.accdb</access_file_path>
      <table_name>Data</table_name>
    </source_info>
    <transfer_interval_hours>240</transfer_interval_hours>
    <retry_interval_minutes>100</retry_interval_minutes>
    <transfer_interval_hours>0</transfer_interval_hours>
    <field_map>
      <Field source="Test_DateTime" target="Test_DateTime" />
      <Field source="UUT_SlotNumber" target="UUT_SlotNumber" />
      <Field source="System_ID" target="System_ID" />      
    </field_map>
    <failure_notification>
      <email_address_list>
        <email_address>bob@abc.com</email_address>
        <email_address>orson@abc.net</email_address>
        <email_address>FrankieJ@abcd.com</email_address>
      </email_address_list>
      <email_subject>Automated Data Transfer Failure</email_subject>
      <email_body>
          Automatic mail.
        </email_body>
    </failure_notification>
  </transfer_configuration>
  <!--A Second Server-->
  <transfer_configuration ID="more_unique_id">
    <!-- ... remaining config information...  -->
  </transfer_configuration>
</config_info>

以及我要验证 xml 的 xsd 架构。架构是

<xsd:schema xmlns:xsd=“http://www.w3.org/2001/XMLSchema”&gt;

    <xsd:complexType name=“DatabaseInfoType”&gt;
        <xsd:sequence>
            <xsd:choice>
                <xsd:element name=“connection_string” type=“string” />
                <xsd:element name=“access_file_path”  >
                    <xsd:simpleType>
                        <xsd:restriction base=“xsd:string”&gt;
                            <xsd:pattern value=“([C-Z]:)|(\\)\\[^%*?\|]+” />
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
            </xsd:choice>
            <xsd:element name=“table_name” type=“string” />
        </xsd:sequence>
        <xsd:attribute name=“ID” type=“string” use=“required” />
    </xsd:complexType>

    <xsd:complexType name=“FieldMapType”&gt;
        <xsd:sequence>
            <xsd:element name=“field” maxOccurs=“unbounded”&gt;          
            </xsd:element>
        </xsd:sequence>
        <xsd:attribute name=“source” type=“xsd:NMTOKEN” use=“required” />
        <xsd:attribute name=“target” type=“xsd:NMTOKEN” use=“required” />
        <xsd:attribute name=“key” type=“xsd:boolean” />
    </xsd:complexType>

    <xsd:complexType name=“PeriodIntervalsType”&gt;
        <xsd:sequence>
            <xsd:element name=“transfer_interval_hours” >
                <xsd:simpleType>
                    <xsd:restriction base=“xsd:positiveInteger”&gt;
                        <xsd:maxInclusive value=“240” />
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name=“retry_interval_minutes”  >
                <xsd:simpleType>
                    <xsd:restriction base=“xsd:positiveInteger”&gt;
                        <xsd:maxInclusive value=“100” />
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name=“initial_interval_minutes”  >
                <xsd:simpleType>
                    <xsd:restriction base=“xsd:positiveInteger”&gt;
                        <xsd:maxInclusive value=“100” />
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name=“FailureNotificationType”&gt;
        <xsd:sequence>
            <xsd:element name=“email_to”&gt;
                <xsd:simpleType>
                    <xsd:restriction base=“xsd:string”&gt;
                        <xsd:pattern value=“([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})” />
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name=“email_subject” type=“string” />
            <xsd:element name=“email_body”    type=“string” />
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name=“TransferConfigType” >
        <xsd:sequence>
            <xsd:element name=“target_info” type=“DatabaseInfoType” />
            <xsd:element name=“source_info” type=“DatabaseInfoType” />
            <xsd:element name=“intervals” type=“PeriodIntervalsType” />
            <xsd:element name=“field_map”   type=“FieldMapType” />            
            <xsd:element name=“failure_notification” type=“FailureNotificationType” />
        </xsd:sequence>
    </xsd:complexType>    

    <xsd:element name=“config_info”&gt;
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name=“transfer_configuration” type=“TransferConfigType” maxOccurs=“unbounded” />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

</xsd:schema>

但是当我执行命令时

xmlFile.Validate(ConfigValHandler),我收到错误,因为“类型'字符串'未声明,或者不是简单类型。”

ConfigValHandler 是 XML 验证的错误处理程序。我无法找到解决方案。

4

1 回答 1

0

是否以下内容被定义为字符串而不是 xs:string?

“xsd:元素名称=“连接字符串”类型=“字符串””

于 2013-08-01T09:30:38.867 回答