Attribute name="nonEmptyString"  not allowed in xs:simpletype

Member_2_7967608
Member_2_7967608 used Ask the Experts™
on
Hi all,

I get the error in the below code in .NET schema validation. The schema file is shared by some one else using J2EE.  My client is .NET.

"Attribute name="nonEmptyString"  not allowed" => in xs:simpletype


<xs:element name="ID" minOccurs="1" nillable="false">
        <xs:simpleType   name="nonEmptyString">
          <xs:restriction base="xs:string">
            <xs:pattern value="(\s*[^\s]\s*)+"/>
            <xs:maxLength value="15"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Information Architect
Top Expert 2006
Commented:
you can only name global declarations and then reference them as type

    <xs:element name="ID" minOccurs="1" nillable="false" type="nonEmptyString"/>
    
    
    <xs:simpleType   name="nonEmptyString">
        <xs:restriction base="xs:string">
            <xs:pattern value="(\s*[^\s]\s*)+"/>
            <xs:maxLength value="15"/>
        </xs:restriction>
    </xs:simpleType>

Open in new window

Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
that is actually the only point of naming them

Author

Commented:
I am still getting the same error with the below code.

<xs:element name="ID" minOccurs="1" nillable="false" type="nonEmptyString"/>
    <xs:simpleType   name="nonEmptyString">
        <xs:restriction base="xs:string">
            <xs:pattern value="(\s*[^\s]\s*)+"/>
            <xs:maxLength value="15"/>
        </xs:restriction>
 </xs:simpleType>

Open in new window

Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
Because you are not showing the context
You need to move the named simple type up to the global level ( as a direct child of the schema element)

Author

Commented:
Below in general is the xsd structure. I haven't included all the elements.  The issue is this XSD is provided by different team. They have specific structure for the Order Payload.   I can tell them "name" attribute is not supported.
<xs:element name="ID"  is the new field they have added.

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns="http://xyxnx.zzz.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xyxnx.zzz.com" elementFormDefault="qualified">
  <xs:element name="OrderTransactions">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="Order" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="Order" type="TransactionType"/>
  <xs:complexType name="TransactionType">
    <xs:sequence>
      <xs:element name="NewCode" minOccurs="1">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:maxLength value="30"/>
            <xs:enumeration value="LXA"/>
            <xs:enumeration value="ESM"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element name="ID" minOccurs="1" nillable="false">
        <xs:simpleType   name="nonEmptyString">
          <xs:restriction base="xs:string">
            <xs:pattern value="(\s*[^\s]\s*)+"/>
            <xs:maxLength value="15"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

Open in new window

Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
You can only reference named types that are globally declared (as I said two times before)
Local type declarations need to be anonymous (that of course makes sense, if not you might have ambiguity)

@name is allowed but only on global declarations (directly below root)

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns="http://xyxnx.zzz.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xyxnx.zzz.com" elementFormDefault="qualified">
    <xs:element name="OrderTransactions">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Order" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    
    <xs:element name="Order" type="TransactionType"/>
    <xs:complexType name="TransactionType">
        <xs:sequence>
            <xs:element name="NewCode" minOccurs="1">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:maxLength value="30"/>
                        <xs:enumeration value="LXA"/>
                        <xs:enumeration value="ESM"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element name="ID" minOccurs="1" nillable="false" type="nonEmptyString">
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    
    <xs:simpleType   name="nonEmptyString">
        <xs:restriction base="xs:string">
            <xs:pattern value="(\s*[^\s]\s*)+"/>
            <xs:maxLength value="15"/>
        </xs:restriction>
    </xs:simpleType>
    
</xs:schema>

Open in new window


Is a working version of your schema (and an implementation of an advice posted twice before)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial