Hi All,

We have to create a schema for the below.
05 :LSRR:-CARD-INFORMATION-GROUP.
10 :LSRR:-CARD-INFORMATION-COUNT PIC 9(04).
10 :LSRR:-CARD-INFORMATION OCCURS 1 TO 1000 TIMES
DEPENDING ON
:LSRR:-CARD-INFORMATION-COUNT

15 :LSRR:-CARDSEQUENCENUMBER PIC 9(04).
15 :LSRR:-CARDNUMBER PIC X(19).
10 :Next field


The field LSRR:-CARD-INFORMATION occurs 1000 times depending on the LSRR:-CARD-INFORMATION-COUNT. Does anyone has a sample schema where in a tag can repeat based on another variable. We can create a schema based on that.

Dani AI

Generated

As describes, the COBOL layout is a group with a count field that controls how many card-information entries appear (1..1000). That exact cross-field constraint cannot be enforced in XML Schema 1.0. Practical options are: (1) use XML Schema 1.1 assertions to check that the number of repeating elements equals the count, (2) keep maxOccurs="1000" in XSD 1.0 and validate the count in application code, or (3) validate with Schematron or an XSLT rule.

A compact XSD 1.1 approach (illustrative) uses vc:minVersion="1.1" and an xs:assert that compares count() of the repeating element to the integer value of the count element:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
           vc:minVersion="1.1">

  <xs:element name="LSRR_CARD_INFORMATION_GROUP">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="LSRR_CARD_INFORMATION_COUNT" type="CountType"/>
        <xs:element name="LSRR_CARD_INFORMATION" minOccurs="1" maxOccurs="1000">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="LSRR_CARDSEQUENCENUMBER" type="FourDigits"/>
              <xs:element name="LSRR_CARDNUMBER" type="CardNumber19"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>

      <xs:assert test="count(LSRR_CARD_INFORMATION) = xs:integer(normalize-space(LSRR_CARD_INFORMATION_COUNT))"/>
    </xs:complexType>
  </xs:element>

  <xs:simpleType name="CountType">
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="1"/>
      <xs:maxInclusive value="1000"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="FourDigits">
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-9]{4}"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="CardNumber19">
    <xs:restriction base="xs:string">
      <xs:length value="19"/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>

Notes and troubleshooting:

  • XSD 1.1 assertions require a validator that supports 1.1 (many do not). If you cannot use 1.1, validate the count in code or with Schematron.
  • Use normalize-space() or explicit casting in the assertion to avoid whitespace/formatting issues.
  • If COBOL preserves leading zeros (PIC 9(04)), represent sequence numbers as strings with a [0-9]{4} pattern rather than plain integer.
  • If the COBOL lower bound were 0, set minOccurs="0"; here 1..1000 maps to minOccurs="1" maxOccurs="1000".

For the XSD 1.1 assertion syntax and rules see the W3C XML Schema 1.1 spec (assertions): XML Schema 1.1 Assertions.

05  :LSRR:-CARD-INFORMATION-GROUP.
               10  :LSRR:-CARD-INFORMATION-COUNT       PIC 9(04).
               10  :LSRR:-CARD-INFORMATION OCCURS 1 TO 1000 TIMES
                                         DEPENDING ON
                                         :LSRR:-CARD-INFORMATION-COUNT
                                         
                   15  :LSRR:-CARDSEQUENCENUMBER       PIC 9(04).
                   15  :LSRR:-CARDNUMBER               PIC X(19).
	       10 :Next field

For better reading

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.