XSD: Enumeration can contain more than one attribute? - xsd

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>

Related

Can we choose from different attribute group in xsd?

Can we do the following? If not, can you guide me to choose the attribute group in xsd.
<xsd:complexType name="getGroupType">
<xsd:choice minOccurs="1" maxOccurs="1">
<xsd:attributeGroup ref="groupA"/>
<xsd:attributeGroup ref="groupB"/>
</xsd:choice>
</xsd:complexType>
xsd:choice is called a model group and can only be used with elements, not with attributes. However, it may be possible to emulate a choice on an attribute group using subtypes (two types extending a base one).

The namespace of element 'enumeration' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'

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>

How can i add dynamic list to enumeration to simpletype(dropdown) using XSD?

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.

What should be the value that i can pass other than X for an CHECKBOXTYPE in XML

Hi all i am an XML Schema where i have the following
<xsd:element name="Check" type="CheckboxType">
<xsd:annotation>
<xsd:documentation>
<Description>Check</Description>
<LineNumber>12</LineNumber>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
While assigning the value or inner text for this field it is taking only X. What's the other value that i can pass other than X. I think X is assigned when i checked a check box, but what's the other value that i can assign to that Node when check box was not checked
There are multiple ways to specify an absence of a value. Below two are two generic ways.
Option 1
Do not add the element in the XML instance. If this is the right option or not is dependent upon the context and hard to tell without knowing more information
Option 2
Use xsi:nil="true" attribute in the XML instance. You can read more about the usage on zvon.org. To use this change your element definition as below
<xsd:element name="Check" type="CheckboxType" nillable="true">
<xsd:annotation>
<xsd:documentation>
<Description>Check</Description>
<LineNumber>12</LineNumber>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
You can then have the XML instance as below
<Check xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />

XSD Schema Validation for 6 or 8 length

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>

Resources