Xsd.exe 架构错误:未定义的复杂类型 'http://www.w3.org/2001/XMLSchema:string'用作复杂类型限制的基础

发布于 2024-10-02 08:00:04 字数 1632 浏览 0 评论 0原文

如何解决这个问题呢?

警告 2 未定义的复杂类型“http://www.w3.org/2001/XMLSchema:string”用作复杂类型限制的基础。

发生这种情况是因为

<xs:element name='TO'>
    <xs:complexType>
      <xs:simpleContent>
        <xs:restriction base='xs:string'>
          <xs:maxLength value='15'/>
          <xs:attribute name='PROVID'>
            <xs:simpleType>
              <xs:restriction base='xs:int'>
                <xs:enumeration value='1'/>
                <xs:enumeration value='2'/>
                <xs:enumeration value='3'/>
                <xs:enumeration value='5'/>
                <xs:enumeration value='6'/>
                <xs:enumeration value='7'/>
              </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
          <xs:attribute name='TYPE'>
            <xs:simpleType>
              <xs:restriction base='xs:string'>
                <xs:enumeration value='NPM'/>
                <xs:enumeration value='EMS'/>
              </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
        </xs:restriction>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>
</xs:schema>

查看 W3schools 参考 这看起来不错,但不是根据 VS2010 和 Xsd.exe

我真正想做的是有一个定义可以具有上述两个属性的元素 TO 及其元素文本应限制为 15 个字符。

How to solve this problem?

Warning 2 Undefined complexType 'http://www.w3.org/2001/XMLSchema:string' is used as a base for complex type restriction.

This is happening because of <xs:simpleContent><xs:restriction base='xs:string'>

<xs:element name='TO'>
    <xs:complexType>
      <xs:simpleContent>
        <xs:restriction base='xs:string'>
          <xs:maxLength value='15'/>
          <xs:attribute name='PROVID'>
            <xs:simpleType>
              <xs:restriction base='xs:int'>
                <xs:enumeration value='1'/>
                <xs:enumeration value='2'/>
                <xs:enumeration value='3'/>
                <xs:enumeration value='5'/>
                <xs:enumeration value='6'/>
                <xs:enumeration value='7'/>
              </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
          <xs:attribute name='TYPE'>
            <xs:simpleType>
              <xs:restriction base='xs:string'>
                <xs:enumeration value='NPM'/>
                <xs:enumeration value='EMS'/>
              </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
        </xs:restriction>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>
</xs:schema>

looking at the W3schools reference this looks ok, but not according to VS2010 and Xsd.exe

All I really want to do is have a definition for an element TO that can have the two above attributes and its element text should be restricted to 15 characters.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惯饮孤独 2024-10-09 08:00:04

您不能将字符串限制为 15 个字符同时将其扩展为具有属性的复杂类型。如果您首先定义一个受限制的字符串类型,然后扩展它,则不会有问题:

<xs:simpleType name="RestrictedString">
    <xs:restriction base="xs:string">
        <xs:maxLength value="15"/>
    </xs:restriction>   
</xs:simpleType>
<xs:element name="TO">
    <xs:complexType>
        <xs:simpleContent>
            <xs:extension base="RestrictedString">
                <xs:attribute name="PROVID">
                    <xs:simpleType>
                        <xs:restriction base="xs:int">
                            <xs:enumeration value="1"/>
                            <xs:enumeration value="2"/>
                            <xs:enumeration value="3"/>
                            <xs:enumeration value="5"/>
                            <xs:enumeration value="6"/>
                            <xs:enumeration value="7"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:attribute>
                <xs:attribute name="TYPE">
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:enumeration value="NPM"/>
                            <xs:enumeration value="EMS"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:attribute>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
</xs:element>

You can't restrict a string to 15 characters and extend it to be a complex type with attributes at the same time. If you first define a restricted string type and then extend it, you won't have a problem:

<xs:simpleType name="RestrictedString">
    <xs:restriction base="xs:string">
        <xs:maxLength value="15"/>
    </xs:restriction>   
</xs:simpleType>
<xs:element name="TO">
    <xs:complexType>
        <xs:simpleContent>
            <xs:extension base="RestrictedString">
                <xs:attribute name="PROVID">
                    <xs:simpleType>
                        <xs:restriction base="xs:int">
                            <xs:enumeration value="1"/>
                            <xs:enumeration value="2"/>
                            <xs:enumeration value="3"/>
                            <xs:enumeration value="5"/>
                            <xs:enumeration value="6"/>
                            <xs:enumeration value="7"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:attribute>
                <xs:attribute name="TYPE">
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:enumeration value="NPM"/>
                            <xs:enumeration value="EMS"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:attribute>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
</xs:element>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文