3

SDL Tridion uses XML schema definitions to define content stored in Tridion components. XSD can use restrictions/facets or indicators to restrict what's valid for XML nodes.

Chris Summers found some of these accidentally in training, specifically that we can set minOccurs and maxOccurs indicators in SDL Tridion 2011 as in:

<xsd:element name="someField" minOccurs="2" maxOccurs="5" type="xsd:normalizedString">

Andrey Marchuk mentions additional options in the same post:

Indicators

  • MaxValue
  • MinValue

Restrictions

  • FractionDigits
  • MaxLength
  • MinLength
  • Pattern
  • TotalDigits

Btw, are these XSD-specific?

  • IsMaxValueExclusive
  • IsMinValueExclusive

How would I get the *restrictions into the following sample Tridion schema (source)?*

<xsd:schema xmlns="http://createandbreak.net/schema/example" xmlns:tcmi="http://www.tridion.com/ContentManager/5.0/Instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://createandbreak.net/schema/example">
    <xsd:import namespace="http://www.tridion.com/ContentManager/5.0/Instance"></xsd:import>
    <xsd:annotation>
        <xsd:appinfo>
            <tcm:Labels xmlns:tcm="http://www.tridion.com/ContentManager/5.0">
                <tcm:Label ElementName="someField" Metadata="false">someField</tcm:Label>
            </tcm:Labels>
        </xsd:appinfo>
    </xsd:annotation>
    <xsd:element name="Content">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="someField" minOccurs="2" maxOccurs="5" type="xsd:normalizedString">
                    <xsd:annotation>
                        <xsd:appinfo>
                            <tcm:ExtensionXml xmlns:tcm="http://www.tridion.com/ContentManager/5.0"></tcm:ExtensionXml>
                        </xsd:appinfo>
                    </xsd:annotation>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

To take an example from W3Schools, this would be a non-Tridion XSD restricting a field to 5 digits using a regular expression:

<xs:element name="prodid">
  <xs:simpleType>
    <xs:restriction base="xs:integer">
      <xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

I tried changing the xs namespace to xsd but I'm not sure where XSD restrictions would go in the (Tridion) schema.

Alvin Reyes
  • 2,889
  • 16
  • 38
  • Just FYI \d{5} is a slightly more concise encapsulation of your Regex (exactly 5 digits), or if you want up to 5 digits: \d{0,5} – Will Jun 25 '13 at 06:34

3 Answers3

4

I believe the XS and XSD is somewhat irrelevant here. Both are actually namespace prefixes which refer to the same namespace. This is described in this post.

If you look at a sample from the site you quoted (http://www.w3schools.com/schema/default.asp) you will see that the xs namespace prefix refers to http://www.w3.org/2001/XMLSchema which is the same as xsd in the Tridion schema.

E.g.

  • xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  • xmlns:xs="http://www.w3.org/2001/XMLSchema"

therefore xsd is the same as xs.

Or am I completely missing your point?

If you are just looking on how to apply restrictions, this comes from the SDL Tridion docs (here but requires password):

<xsd:element name="NumberFieldWithMultipleFacets">
    <xsd:simpleType>
        <xsd:restriction base="xsd:decimal">
            <xsd:totalDigits value="4"/>
            <xsd:fractionDigits value="2"/>
            <xsd:minInclusive value="10"/>
            <xsd:maxInclusive value="20"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>
Community
  • 1
  • 1
Chris Summers
  • 10,153
  • 1
  • 21
  • 46
1

If you are looking for a list of the possible facets in Xml Schema, then you need to look here. Perhaps then it's a simple matter to check which of these are respected/supported by Tridion

Dominic Cronin
  • 6,062
  • 2
  • 23
  • 56
1

I still miss xsd:ID for example, works in WebForms (yes, from version 1.0), but not in the latest SDL Tridion GUI (except 2013, not tested).

I would like all valid xsd's to work in the Tridion GUI.

And for example, that content editors will see a counter when you limit a text field to be min="30" max="70" characters.

Would be a very nice GUI update. Because it would make WebForms possible in the normal(!) Tridion GUI. Creating new fields will then be possible by content management. Creating new HTML5 webforms (tested!) takes then less then 2 minutes.

So please update the GUI to full xsd support.

Wouter
  • 11
  • 1