1
votes

Below is my XSD. I am getting errors. Could you please validate this?

<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://api.vvz.com/"
            xmlns:vz="http://api.vvz.com/"
            targetNamespace="http://api.vvz.com/">
  <vz:element name="Account">
    <annotation>
      <documentation>
        A sample element
      </documentation>
    </annotation>
    <simpleType name="ID">
    <restriction base="xs:string">
     <pattern value='[a-zA-Z0-9]'/>
    </restriction>
   </simpleType>
     <complexType>
    <complexContent>
     <sequence>
     <element minOccurs="0" maxOccurs="unbounded" name="fieldsToNull"
              nillable="true" type="string"/>
     <element minOccurs="0" maxOccurs="1" name="Id" nillable="true"
              type="vz:ID"/>
    </sequence>
    </complexContent>
   </complexType>
  </vz:element>
</xsd:schema>

The error is

The namespace of element schema must be from schema namespace 'http://www.w3.org/2001/XMLSchema'

Please help me out.

2
Please accept whichever answer has helped you the most. Thanks.kjhughes

2 Answers

4
votes

Your immediate error regarding the target namespace is due to declaring xmlns="http://api.vvz.com/" on xsd:schema. Remove that. You don't want the XSD itself in that namespace; you want the governed XML in that namespace, and that's already achieved via targetNamespace="http://api.vvz.com/".

The rest of your XSD has many errors and unclear goals. Here's one set of consistent repairs that brings it to be valid:

<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:vz="http://api.vvz.com/"
            targetNamespace="http://api.vvz.com/">

  <xsd:element name="Account" type="vz:AccountType">
    <xsd:annotation>
      <xsd:documentation>
        A sample element
      </xsd:documentation>
    </xsd:annotation>
  </xsd:element>

  <xsd:complexType name="AccountType">
    <xsd:sequence>
      <xsd:element minOccurs="0" maxOccurs="unbounded" name="fieldsToNull"
                   nillable="true" type="xsd:string"/>
      <xsd:element minOccurs="0" maxOccurs="1" name="Id" nillable="true"
                   type="vz:IdType"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:simpleType name="IdType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value='[a-zA-Z0-9]'/>
    </xsd:restriction>
  </xsd:simpleType>  

</xsd:schema> 
0
votes

There were a couple of issues:

  • All elements that the schema is made of must be in the XML Schema namespace (use the xsd prefix).
  • The named simple type must be top-level.
  • The references to the builtin type string must also be in the XML Schema namespace (xsd prefix).
  • The element complexContent was extraneous.

    <?xml version="1.0" encoding="windows-1252" ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns="http://api.vvz.com/"
        xmlns:vz="http://api.vvz.com/"
        targetNamespace="http://api.vvz.com/">
        <xsd:simpleType name="ID">
            <xsd:restriction base="xsd:string">
                <xsd:pattern value='[a-zA-Z0-9]'/>
            </xsd:restriction>
        </xsd:simpleType>
        <xsd:annotation>
            <xsd:documentation>
                A sample element
            </xsd:documentation>
        </xsd:annotation>
        <xsd:element name="Account">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element minOccurs="0" maxOccurs="unbounded" name="fieldsToNull"
                        nillable="true" type="xsd:string"/>
                    <xsd:element minOccurs="0" maxOccurs="1" name="Id" nillable="true"
                        type="vz:ID"/>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    </xsd:schema>