如何声明 DTD 元素?
How to declare DTD elements?
我正在做一项作业并得到了我的结果,但是我似乎忘记了在我的 DTD 文件中声明这些元素。我是声明所有元素还是只声明包含额外信息的元素?如果我不清楚,这里是我作业的摘录:
<entry id= 'c01'>
<MetaTags>Business</MetaTags>
<title><brand>HP Pavilion</brand><name>550-112NA</name></title>
<Desciption>While other towers have been standing still, HP has revolutionized the category. From magnified performance and reliability, to its stylish redesign, this HP Pavilion is the best thing to happen to towers in over 20 years.</Desciption>
<Price>€579</Price>
<Image src ="Image1.jpg"/>
<Specs>
<CPU>A10-8750 APU</CPU>
<GPU>Radeon R7</GPU>
<RAM>8 GB DDR3</RAM>
<Storage><HDD> 2TB </HDD><SSD></SSD></Storage>
<OS>Windows 10</OS>
<optional>
<Monitor>LG 22" Full HD TV</Monitor>
<Keyboard>Microsoft Wired Keyboard 600</Keyboard>
<Mouse>Logitech M705 Mouse</Mouse>
</optional>
</Specs>
</entry>
是否必须声明标签条目,但其他元素不需要声明,因为它们没有附加变量?
如果那是正确的,声明会像这样吗:
<!ATTLIST entry id CDATA #REQUIRED>
我希望我能把我的问题说清楚,因为我是 XML.Here 我的 DTD 的新手,如果您需要查看它,并且如果我做错了什么。谢谢!
<!ELEMENT ComputerShop (entry+)>
<!ELEMENT entry (MetaTags, title, Description, Price, Image, Specs)>
<!ELEMENT MetaTags (#PCDATA)>
<!ELEMENT Description (#PCDATA)>
<!ELEMENT Price (#PCDATA)>
<!ELEMENT Image (#PCDATA)>
<!ELEMENT title (brand, name)>
<!ELEMENT brand (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT Specs (CPU, GPU, RAM, Storage, OS, optional)>
<!ELEMENT CPU (#PCDATA)>
<!ELEMENT GPU (#PCDATA)>
<!ELEMENT RAM (#PCDATA)>
<!ELEMENT Storage (HDD | SSD)>
<!ELEMENT OS (#PCDATA)>
<!ELEMENT optional (Monitor | Keyboard | Mouse>
<!ELEMENT Monitor (#PCDATA)>
<!ELEMENT Keyboard (#PCDATA)>
<!ELEMENT Mouse (#PCDATA)>
谢谢!
...I forgot to declare the elements in my DTD file
我想你的意思是 "I forgot to declare the attributes in my DTD file"。
必须声明任何属性(元素上的 "extra information")。
因此您需要在 entry
元素上声明 id
属性,在 Image
元素上声明 src
属性。
以下是您需要进行的其他更改...
DTD 更改
<!ELEMENT Specs (CPU, GPU, RAM, Storage, OS, optional)>
中缺少右括号
声明 HDD 和 SSD 元素:<!ELEMENT HDD (#PCDATA)>
和 <!ELEMENT SDD (#PCDATA)>
optional
的声明需要更改。可能到 <!ELEMENT optional (Monitor | Keyboard | Mouse)*>
(0 次或多次出现显示器、键盘或鼠标(以任何顺序))或到 <!ELEMENT optional (Monitor?, Keyboard?, Mouse?)>
(0 或 1 个显示器后跟 0 或 1 个键盘后跟 0 或 1 个鼠标) .
XML 变化
Description
拼错为 Desciption
.
Storage
的内容是一个HDD
或者一个SSD
;不是都。去掉空的<SSD></SSD>
.
这是更正后的文件...
DTD
<!ELEMENT ComputerShop (entry+)>
<!ELEMENT entry (MetaTags, title, Description, Price, Image, Specs)>
<!ATTLIST entry id CDATA #REQUIRED>
<!ELEMENT MetaTags (#PCDATA)>
<!ELEMENT Description (#PCDATA)>
<!ELEMENT Price (#PCDATA)>
<!ELEMENT Image (#PCDATA)>
<!ATTLIST Image src CDATA #REQUIRED>
<!ELEMENT title (brand, name)>
<!ELEMENT brand (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT Specs (CPU, GPU, RAM, Storage, OS, optional)>
<!ELEMENT CPU (#PCDATA)>
<!ELEMENT GPU (#PCDATA)>
<!ELEMENT RAM (#PCDATA)>
<!ELEMENT Storage (HDD | SSD)>
<!ELEMENT HDD (#PCDATA)>
<!ELEMENT SDD (#PCDATA)>
<!ELEMENT OS (#PCDATA)>
<!ELEMENT optional (Monitor | Keyboard | Mouse)*>
<!ELEMENT Monitor (#PCDATA)>
<!ELEMENT Keyboard (#PCDATA)>
<!ELEMENT Mouse (#PCDATA)>
XML
<entry id='c01'>
<MetaTags>Business</MetaTags>
<title><brand>HP Pavilion</brand><name>550-112NA</name></title>
<Description>While other towers have been standing still, HP has revolutionized the category. From magnified performance and reliability, to its stylish redesign, this HP Pavilion is the best thing to happen to towers in over 20 years.</Description>
<Price>€579</Price>
<Image src="Image1.jpg"/>
<Specs>
<CPU>A10-8750 APU</CPU>
<GPU>Radeon R7</GPU>
<RAM>8 GB DDR3</RAM>
<Storage><HDD> 2TB </HDD></Storage>
<OS>Windows 10</OS>
<optional>
<Monitor>LG 22" Full HD TV</Monitor>
<Keyboard>Microsoft Wired Keyboard 600</Keyboard>
<Mouse>Logitech M705 Mouse</Mouse>
</optional>
</Specs>
</entry>
我正在做一项作业并得到了我的结果,但是我似乎忘记了在我的 DTD 文件中声明这些元素。我是声明所有元素还是只声明包含额外信息的元素?如果我不清楚,这里是我作业的摘录:
<entry id= 'c01'>
<MetaTags>Business</MetaTags>
<title><brand>HP Pavilion</brand><name>550-112NA</name></title>
<Desciption>While other towers have been standing still, HP has revolutionized the category. From magnified performance and reliability, to its stylish redesign, this HP Pavilion is the best thing to happen to towers in over 20 years.</Desciption>
<Price>€579</Price>
<Image src ="Image1.jpg"/>
<Specs>
<CPU>A10-8750 APU</CPU>
<GPU>Radeon R7</GPU>
<RAM>8 GB DDR3</RAM>
<Storage><HDD> 2TB </HDD><SSD></SSD></Storage>
<OS>Windows 10</OS>
<optional>
<Monitor>LG 22" Full HD TV</Monitor>
<Keyboard>Microsoft Wired Keyboard 600</Keyboard>
<Mouse>Logitech M705 Mouse</Mouse>
</optional>
</Specs>
</entry>
是否必须声明标签条目,但其他元素不需要声明,因为它们没有附加变量?
如果那是正确的,声明会像这样吗:
<!ATTLIST entry id CDATA #REQUIRED>
我希望我能把我的问题说清楚,因为我是 XML.Here 我的 DTD 的新手,如果您需要查看它,并且如果我做错了什么。谢谢!
<!ELEMENT ComputerShop (entry+)>
<!ELEMENT entry (MetaTags, title, Description, Price, Image, Specs)>
<!ELEMENT MetaTags (#PCDATA)>
<!ELEMENT Description (#PCDATA)>
<!ELEMENT Price (#PCDATA)>
<!ELEMENT Image (#PCDATA)>
<!ELEMENT title (brand, name)>
<!ELEMENT brand (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT Specs (CPU, GPU, RAM, Storage, OS, optional)>
<!ELEMENT CPU (#PCDATA)>
<!ELEMENT GPU (#PCDATA)>
<!ELEMENT RAM (#PCDATA)>
<!ELEMENT Storage (HDD | SSD)>
<!ELEMENT OS (#PCDATA)>
<!ELEMENT optional (Monitor | Keyboard | Mouse>
<!ELEMENT Monitor (#PCDATA)>
<!ELEMENT Keyboard (#PCDATA)>
<!ELEMENT Mouse (#PCDATA)>
谢谢!
...I forgot to declare the elements in my DTD file
我想你的意思是 "I forgot to declare the attributes in my DTD file"。
必须声明任何属性(元素上的 "extra information")。
因此您需要在 entry
元素上声明 id
属性,在 Image
元素上声明 src
属性。
以下是您需要进行的其他更改...
DTD 更改
<!ELEMENT Specs (CPU, GPU, RAM, Storage, OS, optional)>
中缺少右括号
声明 HDD 和 SSD 元素:
<!ELEMENT HDD (#PCDATA)>
和<!ELEMENT SDD (#PCDATA)>
optional
的声明需要更改。可能到<!ELEMENT optional (Monitor | Keyboard | Mouse)*>
(0 次或多次出现显示器、键盘或鼠标(以任何顺序))或到<!ELEMENT optional (Monitor?, Keyboard?, Mouse?)>
(0 或 1 个显示器后跟 0 或 1 个键盘后跟 0 或 1 个鼠标) .
XML 变化
Description
拼错为Desciption
.Storage
的内容是一个HDD
或者一个SSD
;不是都。去掉空的<SSD></SSD>
.
这是更正后的文件...
DTD
<!ELEMENT ComputerShop (entry+)>
<!ELEMENT entry (MetaTags, title, Description, Price, Image, Specs)>
<!ATTLIST entry id CDATA #REQUIRED>
<!ELEMENT MetaTags (#PCDATA)>
<!ELEMENT Description (#PCDATA)>
<!ELEMENT Price (#PCDATA)>
<!ELEMENT Image (#PCDATA)>
<!ATTLIST Image src CDATA #REQUIRED>
<!ELEMENT title (brand, name)>
<!ELEMENT brand (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT Specs (CPU, GPU, RAM, Storage, OS, optional)>
<!ELEMENT CPU (#PCDATA)>
<!ELEMENT GPU (#PCDATA)>
<!ELEMENT RAM (#PCDATA)>
<!ELEMENT Storage (HDD | SSD)>
<!ELEMENT HDD (#PCDATA)>
<!ELEMENT SDD (#PCDATA)>
<!ELEMENT OS (#PCDATA)>
<!ELEMENT optional (Monitor | Keyboard | Mouse)*>
<!ELEMENT Monitor (#PCDATA)>
<!ELEMENT Keyboard (#PCDATA)>
<!ELEMENT Mouse (#PCDATA)>
XML
<entry id='c01'>
<MetaTags>Business</MetaTags>
<title><brand>HP Pavilion</brand><name>550-112NA</name></title>
<Description>While other towers have been standing still, HP has revolutionized the category. From magnified performance and reliability, to its stylish redesign, this HP Pavilion is the best thing to happen to towers in over 20 years.</Description>
<Price>€579</Price>
<Image src="Image1.jpg"/>
<Specs>
<CPU>A10-8750 APU</CPU>
<GPU>Radeon R7</GPU>
<RAM>8 GB DDR3</RAM>
<Storage><HDD> 2TB </HDD></Storage>
<OS>Windows 10</OS>
<optional>
<Monitor>LG 22" Full HD TV</Monitor>
<Keyboard>Microsoft Wired Keyboard 600</Keyboard>
<Mouse>Logitech M705 Mouse</Mouse>
</optional>
</Specs>
</entry>