Yes. Whenever I have to write mind-numbingly repetitive code, or DFDL Schema sections, I write a code/schema generator instead.
So you define a machine-readable format (probably XML) that contains exactly and only the "specification" of what is the essence of these repeating things. Nothing redundant/repetitive. Just the aspects that are different. Then you write a generator that converts your specification into a DFDLSchema, with all the attendant hidden groups and such. Sometimes it is even possible to scrape the XML machine readable "specification" off of a data format spec document. In which case you eliminate the possibility of data entry errors creating the machine readable XML specification. All the large DFDL schemas Tresys has created were done this way. ....mike beckerle Tresys ________________________________ From: Costello, Roger L. <[email protected]> Sent: Friday, March 8, 2019 1:13:21 PM To: [email protected] Subject: How to avoid creating a zillion hidden groups? 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
