could anyone please tell me how to specify the validation rule on XSD for scenario below:
Order number must be exactly either 6 or 8 charater long
<xsd:simpleType name="orderNumber">
<xsd:restriction base="xsd:token">
<xsd:pattern value="[0-9]{6}|[0-9]{8}"/>
</xsd:restriction>
</xsd:simpleType>
Related
Typically we define an enumeration in this way:
<xsd:enumeration value="World"/>
Can another attribute be added besides "value"? For example:
<xsd:enumeration value="World" another="something" />
The xsd:enumeration element doesn’t allow any attributes other than value and id.
It’s not clear from the question what you’re trying to do, but you know you can specify multiple xsd:enumeration elements, right? Isn’t that exactly what the element is for? So you can do this:
<xsd:restriction base="xsd:string">
<xsd:enumeration value="World"/>
<xsd:enumeration value="something"/>
</xsd:restriction>
I am getting this error when validating enumeration element in xsd.
<xsd:restriction base="xsd:unsignedInt">
<enumeration value="4">
</enumeration>
</xsd:restriction>
Please help me regarding this.
s4s-elt-schema-ns: The namespace of element 'enumeration' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'.
The enumeration element need to be bound the XML Schema. You need to add the prefix, namely xsd, like so :
<xsd:enumeration>
Add the namespace prefix xsd: to enumeration:
<xsd:restriction base="xsd:unsignedInt">
<xsd:enumeration value="4"/>
</xsd:restriction>
I have written dorp down element using simpleType restriction using XSD. here is my sample code.
<xsd:simpleType name="StatusListDropDown">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Submitted" />
<xsd:enumeration value="In Process" />
<xsd:enumeration value="Cancelled" />
<xsd:enumeration value="Completed" />
<xsd:enumeration value="Saved" />
</xsd:restriction>
</xsd:simpleType>
Actually my list size is more than 30 records and i don't want to hard code them in same XSD. is there any that i can get them dynamically. One idea is to have separate XSD for this list and import that using xsi:schemaLocation. is it correct way? or is there any good method to do this. please let me know. thank you in advance.
Yes, it's perfectly correct practice to take a frequently-changing enumeration like the one you describe and put it into a separate schema document which can be updated independently of the rest of the schema. You ask for good methods to do this, but I think you have already found the best method.
One technical point: unless you want to place the StatusListDropDown type in a separate namespace, you will want to use xsd:include, not xsd:import to bring it into the main schema document.
I have below complextype
<xsd:complexType name="cidType">
<xsd:choice>
<xsd:sequence>
<xsd:element name="a" type="Type_A"></xsd:element>
<xsd:element name="b" type="Type_B"></xsd:element>
</xsd:sequence>
<xsd:element name="b" type="Type_B"></xsd:element>
</xsd:choice>
</xsd:complexType>
When trying to generate JAXB classes for this schema it's wrong, because, as you see, is repeated reference to the element b the JAXB error gives me is:
/*
* You are getting this "catch-all" property because of the following reason:
* The field name "b" is used by two different parts of a schema.
*/
Since it is an industry standard schema I don't have the liberty to change anything. What is the possible solution?
If i go the customization route, i don't know how to, if possible please point me to a good resource/example. I have already tried my luck with google
I do have an external binding declaration to incorporate data type for some of the elements, but I am not sure how I can use the binding customization to solve my current problem
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.
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>
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
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.