DAP4: DDX Grammar: Difference between revisions

From OPeNDAP Documentation
⧼opendap2-jumptonavigation⧽
No edit summary
No edit summary
Line 1: Line 1:
'''Version: 1.0'''
'''Version: 1.0'''


Below is the formal grammar for the DAP4 DXD, version 1.0.
At the end of this document are instructions for accessing and testing a formal grammar for the DAP4 DDX. I constructed it without any reference to any other explicit or implicit grammars so I could record my proposal. I have since modified it based examining the implied grammar in page [[DAP4: Data Model]]
I constructed it without any reference to any other
and from comments from others.
explicit or implicit grammars so I could record my
proposal.


Now, having looked at the implied grammar in page [[DAP4: Data Model]],
A number of minor issues need to be resolved.
I note at least the following differences.


==== Variable definitions ====
1. Should all element names (e.g. <structure>) be capitalized?
I use the notation:
<pre><variable name="v1" type="int32">... </pre>
as opposed to using the typename as the element tag.
<pre><Int32 name="v1>...</pre>
 
I actually prefer the second notation, but it potentially interferes with
my attempt to provide the equivalent of named user-defined types.
That is, I want to give a name to, for example, a structure definition
<pre><structure name="struct">...</pre>
so that I can allow that type name to be used in variable


2. When should we use nested element names versus an attribute whose value is a list of names.  For example, the current grammar stores dimension references for variables as a list in an attribute named "dimensions": e.g. dimensions="dr d1".<br/>
Previously I used this:
<pre>
<pre>
<!-- Relax NG Grammar -->
<dimensions>
 
<dimension name="dr"/>
<!--grammar datatypelibrary="http://opendap.org/DAP4/datatypes.xml"-->
<dimension name="d1"/>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
</dimensions>
 
</pre>
<start>
  <element name="dataset">
    <ref name="groupdef"/>
  </element>
</start>
 
<define name="groupdef">
  <attribute name="name"/>
  <zeroOrMore>
    <element name="attribute"><ref name="attributedef"/></element>
  </zeroOrMore>
  <optional>
    <element name="dimensions">
      <zeroOrMore>
        <element name="dimension"><ref name="dimdef"/></element>
      </zeroOrMore>
    </element>
  </optional>
  <zeroOrMore>
    <element name="variable"><ref name="variabledef"/></element>
  </zeroOrMore>
  <zeroOrMore>
    <element name="group"><ref name="groupdef"/></element>
  </zeroOrMore>
</define>
 
<define name="dimdef">
    <attribute name="name"/>
    <attribute name="size"/>
    <zeroOrMore>
      <element name="attribute"><ref name="attributedef"/></element>
    </zeroOrMore>
</define>


<define name="variabledef">
=== Testing the Grammar ===
  <attribute name="name"/> 
You will need to copy three files:
  <zeroOrMore>
# dap4.rng - this is the grammar file; it uses the Relax-NG schema language (http://relaxng.org/).<br/>This can be obtained from http://dl.dropbox.com/u/53929684/dap4.rng
    <element name="dimension">
# test.xml - this is a test file, that I am growing to cover the whole grammar.<br/>This can be obtained from http://dl.dropbox.com/u/53929684/test.xml
      <attribute name="name"/>
# jing.jar - Jing is a validator that takes the grammar and a test file and checks that the test file conforms to the grammar.<br/>This can be obtained from http://dl.dropbox.com/u/53929684/jing.jar
    </element>
  </zeroOrMore>
  <zeroOrMore>
    <element name="coordinatevar">
      <attribute name="name"/>
    </element>
  </zeroOrMore>
  <choice>
  <attribute name="type"/>
  <element name="structure"><ref name="structuredef"/></element>
  <element name="sequence"><ref name="sequencedef"/></element>
  <element name="grid"><ref name="griddef"/></element>
  </choice>
  <zeroOrMore>
    <element name="attribute"><ref name="attributedef"/></element>
  </zeroOrMore>
</define>


<define name="structuredef">
To use it, do the command:
  <attribute name="name"/>  
  java -jar jing.jar dap4.rng test.xml
  <zeroOrMore>
No output is produced if the validation succeeds, otherwise, error messages are produced.
    <element name="variable"><ref name="variabledef"/></element>
  </zeroOrMore> 
  <zeroOrMore>
    <element name="attribute"><ref name="attributedef"/></element>
  </zeroOrMore>
</define>


<define name="sequencedef">
''-Dennis Heimbigner''
  <attribute name="name"/> 
  <zeroOrMore>
    <element name="variable"><ref name="variabledef"/></element>
  </zeroOrMore> 
  <zeroOrMore>
    <element name="attribute"><ref name="attributedef"/></element>
  </zeroOrMore>
</define>
 
<define name="griddef">
  <attribute name="name"/> 
  <element name="array">
    <element name="variable"><ref name="variabledef"/></element>
  </element>
  <element name="maps">
    <zeroOrMore>
      <element name="variable"><ref name="variabledef"/></element>
    </zeroOrMore> 
  </element>
  <zeroOrMore>
    <element name="attribute"><ref name="attributedef"/></element>
  </zeroOrMore>
</define>
 
<define name="attributedef">
  <attribute name="name"/>
  <attribute name="type"/>
  <optional>
    <attribute name="namespace"/>
  </optional>
  <choice>
    <attribute name="value"/>
    <oneOrMore>
      <element name="value">
        <attribute name="value"/>
      </element>
    </oneOrMore>
  </choice>
</define>
 
</grammar>
</pre>

Revision as of 18:30, 22 February 2012

Version: 1.0

At the end of this document are instructions for accessing and testing a formal grammar for the DAP4 DDX. I constructed it without any reference to any other explicit or implicit grammars so I could record my proposal. I have since modified it based examining the implied grammar in page DAP4: Data Model and from comments from others.

A number of minor issues need to be resolved.

1. Should all element names (e.g. <structure>) be capitalized?

2. When should we use nested element names versus an attribute whose value is a list of names. For example, the current grammar stores dimension references for variables as a list in an attribute named "dimensions": e.g. dimensions="dr d1".
Previously I used this:

<dimensions>
<dimension name="dr"/>
<dimension name="d1"/>
</dimensions>

Testing the Grammar

You will need to copy three files:

  1. dap4.rng - this is the grammar file; it uses the Relax-NG schema language (http://relaxng.org/).
    This can be obtained from http://dl.dropbox.com/u/53929684/dap4.rng
  2. test.xml - this is a test file, that I am growing to cover the whole grammar.
    This can be obtained from http://dl.dropbox.com/u/53929684/test.xml
  3. jing.jar - Jing is a validator that takes the grammar and a test file and checks that the test file conforms to the grammar.
    This can be obtained from http://dl.dropbox.com/u/53929684/jing.jar

To use it, do the command:

java -jar jing.jar dap4.rng test.xml

No output is produced if the validation succeeds, otherwise, error messages are produced.

-Dennis Heimbigner