We'll have to look into the unexpected exception. If you could provide
the stacktrace when you get the bug, that might help us reproduce it.

I think the way I would model this is via a choice and with
backtracking. The first choice branch would have two 4-byte xs:hexBinary
elements and a discriminiator requiring that the first element is all
zeros. If that discriminator fails, then it backtracks and takes the
second branch of the choice, which would just be a 8-byte string with
right NUL padding like we've talked about in previous email threads. For
example:

  <xs:element name="Symbol_Name">
    <xs:complexType>
      <xs:choice>
        <xs:sequence>
          <xs:element name="LeadingZeros" type="xs:hexBinary"
dfdl:length="4" ...>
            <xs:annotation>
              <xs:appinfo source="http://www.ogf.org/dfdl/";>
                <dfdl:discriminator test="{ xs:string(.) eq "00000000" />
              </xs:appinfo>
            </xs:annotation>
          </xs:element>
          <xs:element name="Offset" type="xs:hexBinary" dfdl:length="4"
... />
        </xs:sequence>
        <xs:element name="Name" type="xs:string" dfdl:length="8" ... />
      </xs:choice>
    </xs:complexType>
  </xs:element>


- Steve


On 1/21/19 4:27 PM, Costello, Roger L. wrote:
> Hello DFDL community,
> 
> My input contains 8 bytes. If the first 4 bytes are all zeroes, then the 
> remaining four bytes represent an offset. Otherwise, the 8 bytes represent a 
> null-terminated string. For example, if the input is this:
> 
> 2E 64 61 74 61 00 00 00
> 
> Then the XML output should be this:
> 
> <Name>.data</Name>
> 
> If the input is this:
> 
> 00 00 00 00 12 34 56 78
> 
> Then the XML output should be this:
> 
> <Offset>12345678</Offset>
> 
> I have no idea how to write a DFDL schema for this input. Below is my 
> attempt, 
> but it just produces “An unexpected exception occurred. This is a bug” 
> message.
> 
> Would you give some guidance on how to create a DFDL schema for the input, 
> please?  /Roger
> 
> <xs:elementname="Symbol_Name">
> <xs:complexType>
> <xs:sequence>
> <xs:sequencedfdl:hiddenGroupRef="hidden_hexBinary8_Group"/>
> <xs:choice>
> <xs:sequence>
> <xs:annotation>
> <xs:appinfosource="http://www.ogf.org/dfdl/";>
> <dfdl:discriminatortest="{xs:string(Hidden_byte1) eq '00' and
>                                  xs:string(Hidden_byte2) eq '00' and
>                                  xs:string(Hidden_byte3) eq '00' and
>                                  xs:string(Hidden_byte4) eq '00'}"/>
> </xs:appinfo>
> </xs:annotation>
> <xs:elementname="Offset"type="xs:hexBinary"dfdl:inputValueCalc="{
>                          fn:concat(xs:string(../Hidden_byte8),
>                          xs:string(../Hidden_byte7),
>                          xs:string(../Hidden_byte6),
>                          xs:string(../Hidden_byte5))}"
> />
> </xs:sequence>
> <xs:sequence>
> <xs:annotation>
> <xs:appinfosource="http://www.ogf.org/dfdl/";>
> <dfdl:discriminatortest="{xs:string(Hidden_byte1) ne '00'}"/>
> </xs:appinfo>
> </xs:annotation>
> <xs:elementname="Name"type="xs:string"dfdl:representation="text"
>                          dfdl:encoding="ISO-8859-1"dfdl:inputValueCalc="{
>                          fn:concat(xs:string(../Hidden_byte1),
>                          xs:string(../Hidden_byte2),
>                          xs:string(../Hidden_byte3),
>                          xs:string(../Hidden_byte4),
>                          xs:string(../Hidden_byte5),
>                          xs:string(../Hidden_byte6),
>                          xs:string(../Hidden_byte7),
>                          xs:string(../Hidden_byte8))}"
> />
> </xs:sequence>
> </xs:choice>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> 
> 
> <xs:groupname="hidden_hexBinary8_Group">
> <xs:sequence>
> <xs:elementname="Hidden_byte1"type="hexBinary1"dfdl:outputValueCalc='{ . }'/>
> <xs:elementname="Hidden_byte2"type="hexBinary1"dfdl:outputValueCalc='{ . }'/>
> <xs:elementname="Hidden_byte3"type="hexBinary1"dfdl:outputValueCalc='{ . }'/>
> <xs:elementname="Hidden_byte4"type="hexBinary1"dfdl:outputValueCalc='{ . }'/>
> <xs:elementname="Hidden_byte5"type="hexBinary1"dfdl:outputValueCalc='{ . }'/>
> <xs:elementname="Hidden_byte6"type="hexBinary1"dfdl:outputValueCalc='{ . }'/>
> <xs:elementname="Hidden_byte7"type="hexBinary1"dfdl:outputValueCalc='{ . }'/>
> <xs:elementname="Hidden_byte8"type="hexBinary1"dfdl:outputValueCalc='{ . }'/>
> </xs:sequence>
> </xs:group>
> 
> 
> <xs:simpleTypename="hexBinary1"dfdl:length="1"dfdl:lengthKind="explicit"dfdl:lengthUnits="bytes">
> <xs:restrictionbase="xs:hexBinary"/>
> </xs:simpleType>
> 

Reply via email to