2017-01-10 100 views
-2

我有這樣的DTD:DTD到XML模式

<!DOCTYPE recipes [ <!ELEMENT recipes (Recipe+)> <!ELEMENT Recipe (Title,(Ingredients*|Preparation?),Comments?, Nutrition,Fat,Carbohydrates,Protein)> <!ELEMENT Title (#PCDATA)> <!ELEMENT Ingredients EMPTY> <!ATTLIST Ingredients name CDATA #REQUIRED amount CDATA #IMPLIED unit CDATA #IMPLIED> <!ELEMENT Preparation(steps,filling?,dough?,sauce?)> <!ELEMENT steps (#PCDATA)> <!ELEMENT filling (#PCDATA)> <!ELEMENT dough (#PCDATA)> <!ELEMENT sauce (#PCDATA)> <!ELEMENT Comments (#PCDATA)> <!ATTLIST Nutrition Calories CDATA #REQUIRED> <!ELEMENT Fat EMPTY> <!ATTLIST Fat fat CDATA #IMPLIED> <!ELEMENT Carbohydrates EMPTY> <!ATTLIST Carbohydrates carb CDATA #IMPLIED> <!ELEMENT Protein EMPTY> <!ATTLIST Protein prot CDATA #IMPLIED>
]>

我想將其轉換爲XSD,但我不明白我怎麼所有元素創建屬性,以及如何將整個DTD到XSD?提前致謝。

回答

0

您的DTD沒有爲營養定義的元素,但是如果添加了它,那麼它看起來像是一個XSD。

<?xml version="1.0" encoding="utf-8"?> 
<!--Created with Liquid Studio 2017 - Developer Bundle Edition (Trial) 15.0.0.7084 (https://www.liquid-technologies.com)--> 
<xs:schema elementFormDefault="qualified" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="recipes"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element ref="Recipe" 
        maxOccurs="unbounded" /> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 
    <xs:element name="Recipe"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element ref="Title" /> 
     <xs:choice> 
      <xs:element ref="Ingredients" 
         minOccurs="0" 
         maxOccurs="unbounded" /> 
      <xs:element ref="Preparation" 
         minOccurs="0" /> 
     </xs:choice> 
     <xs:element ref="Comments" 
        minOccurs="0" /> 
     <xs:element ref="Nutrition" /> 
     <xs:element ref="Fat" /> 
     <xs:element ref="Carbohydrates" /> 
     <xs:element ref="Protein" /> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 
    <xs:element name="Title" 
       type="xs:string" /> 
    <xs:element name="Ingredients"> 
    <xs:complexType> 
     <xs:attribute name="name" 
        type="xs:string" 
        use="required" /> 
     <xs:attribute name="amount" 
        type="xs:string" /> 
     <xs:attribute name="unit" 
        type="xs:string" /> 
    </xs:complexType> 
    </xs:element> 
    <xs:element name="Preparation"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element ref="steps" /> 
     <xs:element ref="filling" 
        minOccurs="0" /> 
     <xs:element ref="dough" 
        minOccurs="0" /> 
     <xs:element ref="sauce" 
        minOccurs="0" /> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 
    <xs:element name="steps" 
       type="xs:string" /> 
    <xs:element name="filling" 
       type="xs:string" /> 
    <xs:element name="dough" 
       type="xs:string" /> 
    <xs:element name="sauce" 
       type="xs:string" /> 
    <xs:element name="Nutrition"> 
    <xs:complexType mixed="true"> 
     <xs:attribute name="Calories" 
        type="xs:string" 
        use="required" /> 
    </xs:complexType> 
    </xs:element> 
    <xs:element name="Comments" 
       type="xs:string" /> 
    <xs:element name="Fat"> 
    <xs:complexType> 
     <xs:attribute name="fat" 
        type="xs:string" /> 
    </xs:complexType> 
    </xs:element> 
    <xs:element name="Carbohydrates"> 
    <xs:complexType> 
     <xs:attribute name="carb" 
        type="xs:string" /> 
    </xs:complexType> 
    </xs:element> 
    <xs:element name="Protein"> 
    <xs:complexType> 
     <xs:attribute name="prot" 
        type="xs:string" /> 
    </xs:complexType> 
    </xs:element> 
</xs:schema> 

enter image description here