Restrict type of xsd:any to xsd:string only?

前端 未结 1 1225
伪装坚强ぢ
伪装坚强ぢ 2021-01-20 07:06

So I\'m writing a new XSD and I\'ve come across a little issue. Now I\'ll admit I\'m not the best with these, but I would have thought what I have done should have worked bu

相关标签:
1条回答
  • 2021-01-20 07:19

    XSD 1.1

    See @IanRoberts fine suggestion in the comments regarding asserting that no grandchild elements exist under the children of extraInfo.

    XSD 1.0

    If you want more control over the type of the extraInfo child elements, you'll have to specify their names a priori.

    Attributes

    Or, why not leverage the fact that attribute values already are constrained not to have subelements and use xsd:anyAttribute instead:

      <xsd:element name="extraInfo">
        <xsd:complexType>
          <xsd:anyAttribute processContents="skip" />
        </xsd:complexType>
      </xsd:element>
    

    Users could then add extraInfo along these lines:

    <extraInfo
         logoUrl="http://www.google.com/logo.png"
         cssUrl="http://www.google.com/main.css"/>
    

    and

    <extraInfo
        headerText="Hello World"
        footerText="Goodbye World"/>
    

    which would be natural given that you wish to allow only string values.

    Elements (update per OP question in comments)

    If the max of 42 constraint is important to you, you could go meta with a structure such as

    <extraInfo>
        <item name="logoUrl" value="http://www.google.com/logo.png"/>
        <item name="cssUrl" value="http://www.google.com/main.css"/>
    </extraInfo>
    

    Then you could restrict the number of item elements trivially in XSD 1.0 via @maxOccurs.

    0 讨论(0)
提交回复
热议问题