0

I stuck with the following conversion from DTD:

<!ELEMENT contact (name+, ((email | phone+) | (email, phone+)), address?)>

to XSD:

<xs:element name="contact">
<xs:complexType>
  <xs:sequence>
    <xs:element maxOccurs="unbounded" ref="name"/>
    <xs:choice>
      <xs:choice>
        <xs:element ref="email"/>
        <xs:element maxOccurs="unbounded" ref="phone"/>
      </xs:choice>
      <xs:sequence>
<!-- Next line causes exception -->
        <xs:element ref="email"/>
        <xs:element maxOccurs="unbounded" ref="phone"/>
      </xs:sequence>
    </xs:choice>
    <xs:element minOccurs="0" ref="address"/>
  </xs:sequence>
</xs:complexType>

I get 'Multiple definition of element 'email' causes the content model to become ambiguous.' exception. What I do wrong? any suggestions to overcome

Andrey Borisko
  • 4,511
  • 2
  • 22
  • 31

1 Answers1

1

The DTD content model is ambiguous, so the converter has generated an ambiguous content model in the schema. Both DTD and XSD prohibit ambiguous content models.

"Ambiguity" here is a technical term, it means that when an "email" element is found in the input, it can't tell which branch of the choice to take. There are different kinds of ambiguity - some can be resolved by lookahead, others can't; but that's irrelevant here. If you feed a bad DTD into the converter, you will get a bad schema out.

In this particular case, removing the ambiguity is trivial, just change the content model to

<!ELEMENT contact (name+, email, phone+, address?)>

In the more general case, removing ambiguities is a difficult (but solved) problem in computer science.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • I didn't realize that DTD isn't valid, it was given from trusted source and finished state project. I'm going to check it now. – Andrey Borisko Jul 14 '12 at 15:46