qiuwei / jing-trang

Automatically exported from code.google.com/p/jing-trang
Other
1 stars 1 forks source link

Default values not generated when convertng from rng to dtd #141

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. I have a schema with defaulted attributes
2. I converted this with http://code.google.com/p/xsdtorngconverter/ to a Relax 
NG schema
3. I then converted this RNG schema with Trang 20091111 into a DTD

What is the expected output? What do you see instead?
I expect an attribute with a default value instead of a #REQUIRED attribute. In 
fact all attributes which are defined as a single attribute will have the 
#REQUIRED tag even if they are #IMPLIED

What version of the product are you using? On what operating system?
I'm using trang2009111

Please provide any additional information below.
I've been searching in the code and found a section in the module 
DTDOutput.java which might cause the wrong behaviour. It is in the method 
visitAttribute. There is a test on isRequired() which always returns true and 
len==1. My guess is that this test does not cover all cases. When there is only 
one attribute the part for the default value is never reached.
Is this by design or is this a bug?

Original issue reported on code.google.com by peet...@gmail.com on 28 Apr 2011 at 7:58

GoogleCodeExporter commented 8 years ago
Please post a small sample RNG that you convert to DTD that can be used to 
reproduce the problem (we should remove the conversion from XML Schema to Relax 
NG as that is part of a different project). Add also the DTD fragment that you 
expect as the result of converting that RNG file.

Original comment by georgebina76 on 8 Aug 2011 at 12:30

GoogleCodeExporter commented 8 years ago
I think I have the same problem when converting from RNG to XSD. More 
specifically, I have one attribute defined as required (i.e. not inside an 
<optional> element in the RNG), which seems to override all other instances of 
that attribute. In the resulting XSD, that attribute is globally defined as 
@use="required", when I have set it to be optional in most elements. See also 
the recent discussion on TEI-L, 
<http://tei-l.970651.n3.nabble.com/ODD-problem-xml-id-missing-or-wrong-usage-in-
XSD-td4024120.html>.

Original comment by martin.d...@gmail.com on 3 Jul 2013 at 9:54

GoogleCodeExporter commented 8 years ago
OK, here's a snippet from my RNG:

<define name="att.global.attribute.xmlid">
      <optional>
         <attribute name="xml:id">
            <data type="ID"/>
         </attribute>
      </optional>
   </define>

   <define name="milestone">
      <element name="milestone">
         <ref name="att.global.attribute.xmlid"/>
      </element>
   </define> 

   <define name="glyph">
      <element name="glyph">
         <attribute name="xml:id">
            <a:documentation xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"/>
            <choice>
               <value>x</value>
               <a:documentation xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"/>
               <value>y</value>
               <a:documentation xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"/>
               <value>z</value>
               <a:documentation xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"/>
            </choice>
         </attribute>
         <empty/>
      </element>
   </define>

As you can see, the first element references the optional attribute @xml:id, 
whereas the second element defines a required attribute @xml:id. This is what I 
get when I convert the RNG to XSD via Roma (in the xml.xsd):

<xs:attributeGroup name="id">
    <xs:attribute name="id" use="required" form="qualified" type="xs:ID">
      <xs:annotation>
        <xs:documentation>(identifier) provides a unique identifier for the element bearing the attribute.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:attributeGroup>

  <xs:attributeGroup name="id1">
    <xs:attribute name="id" use="required" form="qualified">
      <xs:simpleType>
        <xs:restriction base="xs:token">
          <xs:enumeration value="x"/>
          <xs:enumeration value="y"/>
          <xs:enumeration value="z"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:attributeGroup>

So both id and id1 have @use="required", when I wanted id (the first one) to be 
optional.

Original comment by martin.d...@gmail.com on 10 Jul 2013 at 8:39

GoogleCodeExporter commented 8 years ago
OK, here's a snippet from my RNG:

<define name="att.global.attribute.xmlid">
      <optional>
         <attribute name="xml:id">
            <data type="ID"/>
         </attribute>
      </optional>
   </define>

   <define name="milestone">
      <element name="milestone">
         <ref name="att.global.attribute.xmlid"/>
      </element>
   </define> 

   <define name="glyph">
      <element name="glyph">
         <attribute name="xml:id">
            <a:documentation xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"/>
            <choice>
               <value>x</value>
               <a:documentation xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"/>
               <value>y</value>
               <a:documentation xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"/>
               <value>z</value>
               <a:documentation xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"/>
            </choice>
         </attribute>
         <empty/>
      </element>
   </define>

As you can see, the first element references the optional attribute @xml:id, 
whereas the second element defines a required attribute @xml:id. This is what I 
get when I convert the RNG to XSD via Roma (in the xml.xsd):

<xs:attributeGroup name="id">
    <xs:attribute name="id" use="required" form="qualified" type="xs:ID">
      <xs:annotation>
        <xs:documentation>(identifier) provides a unique identifier for the element bearing the attribute.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:attributeGroup>

  <xs:attributeGroup name="id1">
    <xs:attribute name="id" use="required" form="qualified">
      <xs:simpleType>
        <xs:restriction base="xs:token">
          <xs:enumeration value="x"/>
          <xs:enumeration value="y"/>
          <xs:enumeration value="z"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:attributeGroup>

So both id and id1 have @use="required", when I wanted id (the first one) to be 
optional.

Original comment by martin.d...@gmail.com on 10 Jul 2013 at 8:41

GoogleCodeExporter commented 8 years ago
OK, here's a snippet from my RNG:

<define name="att.global.attribute.xmlid">
      <optional>
         <attribute name="xml:id">
            <data type="ID"/>
         </attribute>
      </optional>
   </define>

   <define name="milestone">
      <element name="milestone">
         <ref name="att.global.attribute.xmlid"/>
      </element>
   </define> 

   <define name="glyph">
      <element name="glyph">
         <attribute name="xml:id">
            <a:documentation xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"/>
            <choice>
               <value>x</value>
               <a:documentation xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"/>
               <value>y</value>
               <a:documentation xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"/>
               <value>z</value>
               <a:documentation xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"/>
            </choice>
         </attribute>
         <empty/>
      </element>
   </define>

As you can see, the first element references the optional attribute @xml:id, 
whereas the second element defines a required attribute @xml:id. This is what I 
get when I convert the RNG to XSD via Roma (in the xml.xsd):

<xs:attributeGroup name="id">
    <xs:attribute name="id" use="required" form="qualified" type="xs:ID">
      <xs:annotation>
        <xs:documentation>(identifier) provides a unique identifier for the element bearing the attribute.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:attributeGroup>

  <xs:attributeGroup name="id1">
    <xs:attribute name="id" use="required" form="qualified">
      <xs:simpleType>
        <xs:restriction base="xs:token">
          <xs:enumeration value="x"/>
          <xs:enumeration value="y"/>
          <xs:enumeration value="z"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:attributeGroup>

So both id and id1 have @use="required", when I wanted id (the first one) to be 
optional.

Original comment by martin.d...@gmail.com on 10 Jul 2013 at 12:14