我有这个DTD:
<!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 :(得分: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>