xmlxsdjaxbxmlschema

Restricting string length in XML Schema


I am new to XML and JAXB, I am trying to add the AdditionalDataDeposit field with restrictions to my XML schema so I can generate the POJO with Maven. When I try to build it in maven the error:

blahBlahBlahmsgfactory: Unable to parse input schema(s). Error messages should have been provided. 
org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 
'LimitedString50' to a(n) 'type definition' component.

my code:

Under AdditionalData complex type:

<xs:element name="DEPOSIT" type="trmns:AdditionalDataDEPOSIT" minOccurs="0">
  <xs:annotation>
    <xs:documentation>Additional Deposit Data</xs:documentation>
  </xs:annotation>
</xs:element>

then:

  <xs:complexType name="AdditionalDataDEPOSIT">
    <xs:annotation>
      <xs:documentation>Additional Deposit Data</xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="depositorID" type="LimitedString50"/>
      <xs:element name="depositorNationality" type="LimitedString50"/>
      <xs:element name="fundSource" type="LimitedString50"/>
      <xs:element name="fullName" type="LimitedString100"/>
    </xs:sequence>
  </xs:complexType>
  <xs:simpleType name="LimitedString50">
    <xs:restriction base="xs:string">
      <xs:maxLength value="50" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="LimitedString100">
    <xs:restriction base="xs:string">
      <xs:maxLength value="100" />
    </xs:restriction>
  </xs:simpleType>

I dont understand much of XML Schema's, but advice will be appreciated.


Solution

  • The error message says that LimitedString50 cannot be resolved to a type definition. That means that it cannot find that type definition. The simple type 'LimitedString50' is defined in the same XSD, so the most likely explanation is that your schema has a non-empty targetNamespace but your type reference does not specify that namespace.

    I cannot verify this because you have not posted your entire XSD.