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

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

Member_2_7967608Asked:
Who is Participating?
 
Geert BormansInformation ArchitectCommented:
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

0
 
Geert BormansInformation ArchitectCommented:
that is actually the only point of naming them
0
 
Member_2_7967608Author 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

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Geert BormansInformation ArchitectCommented:
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)
0
 
Member_2_7967608Author 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

0
 
Geert BormansInformation ArchitectCommented:
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)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.