cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How change enumCodeType Pattern in Item.xsd file?

Former Member
0 Kudos
1,233

I have created an enumtype in the Item.xml file, like this:

     <enumtype generate="true" code="ColcilEnum" autocreate="true" dynamic="true">
         <value code="V"/>
         <value code="01"/>
                     <value code="N/A"/>
                     <value code="4X6"/>
     </enumtype>

But it gives the following error:

"cvc-pattern-valid: Value 'N/A' is not facet-valid with respect to pattern ([a-zA-Z_])+([a-z_A-Z$0-9])*."

I tried to change the item.xsd file, but when execute ant clean all comand, the file return to original code:

           <xs:simpleType name="enumCodeType">
                          <xs:annotation>
                                        <xs:documentation>Configures the code of an enumeration value element. 
                                         Must start with a letter or underscore.</xs:documentation>
                          </xs:annotation>
                          <xs:restriction base="xs:normalizedString" >
                                        <xs:pattern value="([a-zA-Z_])+([a-z_A-Z$0-9])*"/>
                          </xs:restriction>
           </xs:simpleType>
 

Is there any way to change this pattern?.

Thanks, Regards, Aldo

View Entire Topic
geffchang
Active Contributor
0 Kudos

items.xsd is a data definition defined by the Hybris Platform and should be followed / respected. It cannot be modified. If the items.xml does not follow the items.xsd, then it becomes invalid.

For the case of "N/A", I would suggest to remove the forward slash, like this:

  <value code="NA"/>

If you want the slash to be displayed in the UI, you can add a label for the "NA" in locales file (*-locales_en.properties), like this:

 type.ColcilEnum.NA.name=N/A

This way, the code (i.e. "NA") is valid, while having the label (i.e. "N/A") you want.

andyfletcher
Active Contributor
0 Kudos

And the reason for the validation is because this is invalid Java.

 enum Foo { 01, N/A, 4X6 }

The xml definition is used to generate Java code which has to compile!

Enums are Java identifiers and must start with a letter (or underscore or dollar) and can't have slashes in them. (So all of your enum values are invalid)

See the rules on naming here https://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html

geffchang
Active Contributor
0 Kudos

Thanks, Andrew! You're right. I wanted to include this information as well, but Arvind already pointed it out.