0

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.

user3636602
  • 73
  • 1
  • 10

3 Answers3

1

Your XML schema so far I see has only one error: attribute "minOccurs" should not be defined for global elements. So the declaration of DEPOSIT element should look like this:

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

An explanation regarding minOccurs for global elements is given e.g. here.

Daniil
  • 913
  • 8
  • 19
1

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.

kimbert
  • 2,376
  • 1
  • 10
  • 20
0
<xs:complexType name="AdditionalDataDEPOSIT">
    <xs:annotation>
      <xs:documentation>Additional Deposit Data</xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="depositorID" type="trmns:LimitedStringFifty"/>
      <xs:element name="depositorNationality" type="trmns:LimitedStringFifty"/>
      <xs:element name="fundSource" type="trmns:LimitedStringFifty"/>
      <xs:element name="fullName" type="trmns:LimitedStringHundred"/>
    </xs:sequence>
  </xs:complexType>
    <xs:simpleType name="LimitedStringFifty">
      <xs:restriction base="xs:string">
        <xs:maxLength value="50" />
      </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="LimitedStringHundred">
      <xs:restriction base="xs:string">
        <xs:maxLength value="100" />
      </xs:restriction>
    </xs:simpleType>

Adding trmns: to the prefix of my type seemed to work, I'm not entirely sure why, maybe somebody here could explain. Posting to assist others.

user3636602
  • 73
  • 1
  • 10
  • 1
    It works because your _global_ simple type is in the targetNamespace of your xsd. In order to reference that simple type, you _must_ specify its fully qualified name. The prefix 'trmns' is bound to the target namespace of your xsd. Adding the prefix 'trmns:' to your reference is fixing your broken type reference by adding the missing namespace information. – kimbert Feb 19 '20 at 16:50