Hello DFDL community,

In the file format that I am working on, my DFDL schema consumes a numeric 
input value and outputs XML that contains a triple of elements: raw, code, and 
description.

Example: Consume this number (shown as 4 hex bytes, big endian form):

        00 00 00 02

and output this XML:

    <Status>
      <Raw>2</Raw>
      <Code>Starting</Code>
      <Description>The database is loading and initializing 
processes.</Description>
    </Status>

To accomplish that, of course, I need to create a hidden group:

<xs:group name="hidden_status_Group"> 
    <xs:sequence>
        <xs:element name="Hidden_status" type="unsignedint32" 
            dfdl:outputValueCalc="{ ../Status/Raw }" />
    </xs:sequence>
</xs:group>

I need to reference that group:

<xs:sequence dfdl:hiddenGroupRef="hidden_status_Group" />

And I need to declare the <Status> element and its 3 child elements:

<xs:element name="Status">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Raw" type="unsignedint32" 
dfdl:inputValueCalc='{../../Hidden_status}' />
            <xs:element name="Code" type="xs:string" dfdl:inputValueCalc='{
                if (../../Hidden_status eq 0) then "N/A" 
                else if (../../Hidden_status eq 1) then "Down"
                else if (../../Hidden_status eq 2) then "Starting"
                else if (../../Hidden_status eq 3) then "Up"
                else if (../../Hidden_status eq 4) then "Stopping"
                else fn:error("Invalid value for Status")}'>
            </xs:element>
            <xs:element name="Description" type="xs:string" 
dfdl:inputValueCalc='{
                if (../../Hidden_status eq 0) then "Not Used" 
                else if (../../Hidden_status eq 1) then "Database is not 
running."
                else if (../../Hidden_status eq 2) then "Database is loading 
and initializing processes."
                else if (../../Hidden_status eq 3) then "Database is running."
                else if (../../Hidden_status eq 4) then "Database has 
terminated and not responding to commands."
                else fn:error("Status_Response: Invalid value for Status")}'>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

I don't mind doing that once or twice or even a dozen times. But with this file 
format I'll have to do it a hundred times. That means a hundred hidden groups, 
a hundred references to hidden groups, a hundred element declarations. 

Ugh!

It is mind-numbingly boring. 

There has got to be a way to avoid all this repetition.

Can you suggest ways to avoid all this repetition?

/Roger

Reply via email to