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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gertone (Geert Bormans)Information 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gertone (Geert Bormans)Information 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
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Gertone (Geert Bormans)Information 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
Gertone (Geert Bormans)Information 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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.