Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

s4s-att-not-allowed: Attribute 'name' cannot appear in element 'simpleType'

Tags:

xml

xsd

When we specify the name parameter in simpleType, we are getting an error:

"s4s-att-not-allowed: Attribute 'name' cannot appear in element 'simpleType'."

eg:

 <xs:simpleType name="lengthValue">
   <xs:restriction base="xs:string">
     <xs:maxLength value="14"/>
   </xs:restriction>
 </xs:simpleType>

Is this example is correct? Why are we getting an error like above?

like image 342
jomy Avatar asked Oct 17 '25 03:10

jomy


1 Answers

Your fragment may or may not be ok, depending on its context. Since you're getting the given error, it would appear that your context is a local, nested definition, where @name is not allowed.

xs:simpleType MAY be given a name when used globally. This is ok:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:simpleType name="lengthValue">
    <xs:restriction base="xs:string">
      <xs:maxLength value="14"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>

xs:simpleType may NOT be given a name when used globally. This is NOT ok:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="e">
    <xs:simpleType name="lengthValue">
      <xs:restriction base="xs:string">
        <xs:maxLength value="14"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>

To solve the problem:

Either

  • remove the name attribute, or
  • make the definition of lengthValue be global, and reference it using @type:

Here is an example of how to use @name with xs:simpleType:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:simpleType name="lengthValue">
    <xs:restriction base="xs:string">
      <xs:maxLength value="14"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:element name="e" type="lengthValue"/>
</xs:schema>
like image 186
kjhughes Avatar answered Oct 18 '25 19:10

kjhughes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!