dizzzz / jing-trang

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

Conversion from DTD to XSD fails on very simple case. #144

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Convert the following DTD to XSD

<!ELEMENT title    (#PCDATA)>
<!ELEMENT desc    (#PCDATA)>
<!ELEMENT tgroup    (#PCDATA)>

<!ENTITY % tbl.table-titles.mdl "((title)?, (desc)?)?,">
<!ENTITY % tbl.table-main.mdl   "(tgroup)+">

<!ELEMENT table    (%tbl.table-titles.mdl; %tbl.table-main.mdl;)>

2. The following schema will be produced: 

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
elementFormDefault="qualified">
  <xs:element name="title" type="xs:string"/>
  <xs:element name="desc" type="xs:string"/>
  <xs:element name="tgroup" type="xs:string"/>
  <xs:group name="tbl.table-titles.mdl">
    <xs:sequence>
      <xs:sequence minOccurs="0">
        <xs:element minOccurs="0" ref="title"/>
        <xs:element minOccurs="0" ref="desc"/>
      </xs:sequence>
    </xs:sequence>
  </xs:group>
  <xs:group name="tbl.table-main.mdl">
    <xs:sequence>
      <xs:element maxOccurs="unbounded" ref="tgroup"/>
    </xs:sequence>
  </xs:group>
  <xs:element name="table">
    <xs:complexType>
      <xs:choice>
        <xs:group ref="tbl.table-titles.mdl"/>
        <xs:group ref="tbl.table-main.mdl"/>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

Of particular interest is this section:

<xs:element name="table">
    <xs:complexType>
      <xs:choice>
        <xs:group ref="tbl.table-titles.mdl"/>
        <xs:group ref="tbl.table-main.mdl"/>
      </xs:choice>
    </xs:complexType>
  </xs:element>

Which presents a choice instead of a sequence.

3. Test the original DTD and the Schema against this XML file:

<table>
    <title/>
    <tgroup/>   
</table>

The DTD reports this as valid, the schema reports <tgroup/> as being invalid.

What is the expected output? What do you see instead?

I would expect that 

<!ELEMENT table    (%tbl.table-titles.mdl; %tbl.table-main.mdl;)>

would be converted to

<xs:element name="table">
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="tbl.table-titles.mdl"/>
        <xs:group ref="tbl.table-main.mdl"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

What version of the product are you using? On what operating system?

Using Trang version 20091111 on ubuntu 10.10.

Please provide any additional information below.

I am not an expert on DTD's so I do not fully understand how the former is 
interperated, or how to fix but I have ran this test on a number of document 
sets and gotten the same results.

This directly effects the conversion of DITA DTD's to XSD as the above example 
is a simplified version of the problem I encountered with the full DITA 
language DTD's. This has also been tested against vairous grammars in the DITA 
Open Toolkit V1.5.2

Original issue reported on code.google.com by opportun...@easydita.com on 3 Jun 2011 at 10:59

GoogleCodeExporter commented 8 years ago
This also occurs in trunk. After some digging it seems that this problem stems 
from this line in Particle.java in the particlesToModelGroup() method:

if (p.entity.parsed.size() == 0 && ((p.entity.groupFlags & 
Entity.GROUP_CONTAINS_SEQ) != 0))
isSequence = true;

Specifically p.entity.parsed.size() is not equal to zero when parsing something 
like:

<!ELEMENT table    (%tbl.table-titles.mdl; %tbl.table-main.mdl;)>

However, the logic behind this is a mystery to me. I would think that since 
these are purely referenced entities do not contain any modifiers like (,|) 
this should always be treated as a sequence...

I will continue digging. Any help would be much appreciated. I need to fix this 
asap.

Thanks.

Original comment by opportun...@easydita.com on 4 Jun 2011 at 3:36

GoogleCodeExporter commented 8 years ago
I've run into the same problem converting the DITA DTD to RELAX NG. The 
erroneous output is

  <define name="tbl.table.mdl">
    <choice>
      <ref name="tbl.table-titles.mdl"/>
      <ref name="tbl.table-main.mdl"/>
    </choice>
  </define>

Original comment by mblaze...@stilo.com on 23 Nov 2011 at 8:04