我可以将 !ATTLIST 功能组合到 DTD 的一行中吗?
我刚刚学习编写 XML 和相关的 DTD,我想知道是否可以将某些内容组合到 !ATTLIST 的一行中。
例如:
我有一个元素 weight
,我希望将 (kg|lb)
作为选项,但将 "kg"
设置为默认值。这些都不是必需的,因此状态为#IMPLIED,但我也希望默认权重为“1”。
我可以合法地将所有这些放在一行中吗:
<!ELEMENT weight (#PCDATA)>
<!ATTLIST weight unit CDATA "1" (kg|lb) "kg" #IMPLIED>
或者我可以这样做吗:
<!ELEMENT weight (#PCDATA)>
<!ATTLIST weight unit CDATA>
<!ATTLIST weight unit "1" #IMPLIED>
<!ATTLIST weight unit (kg|lb)>
<!ATTLIST weight unit "kg" #IMPLIED>
我怀疑两者都存在问题,并且我对如何组合这些功能(或者如果我什至可以)感到有点困惑 - 所以我会非常感谢有关正确执行此操作的一些指导。
I am just learning to write XML and associated DTD's, and I'm wondering if I can combine certain things in one line of an !ATTLIST.
eg:
I have an element weight
, and I want to have (kg|lb)
as options, but set "kg"
as the default. None of these are essential, so the status is #IMPLIED
, but I also want to have a default weight of "1".
Can I legally put all this in one line:
<!ELEMENT weight (#PCDATA)>
<!ATTLIST weight unit CDATA "1" (kg|lb) "kg" #IMPLIED>
Or can I do it this way:
<!ELEMENT weight (#PCDATA)>
<!ATTLIST weight unit CDATA>
<!ATTLIST weight unit "1" #IMPLIED>
<!ATTLIST weight unit (kg|lb)>
<!ATTLIST weight unit "kg" #IMPLIED>
I suspect there are problems with both, and I am a little confused as to how I combine these features (or if I even can) - so I would really appreciate a little guidance on doing this properly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我已经通过执行以下操作使其正常工作,尽管这可能不是“公认的做法”方式:
我必须将值分解为它自己的属性(现在我想这很有意义),并删除 #暗示,因为我在某处读到通过设置默认值,无论如何它都是暗示的。
希望这对其他人有帮助(假设这是正确的方法)
干杯
Ok, I have got it working by doing the following, although it might not be the 'accepted practice' way:
I had to break the value out into its own attribute (which makes sense now I think about it), and remove the #IMPLIED, since I read somewhere that by setting a default value, its implied anyway.
Hopefully this will help someone else (assuming its the right way to do it)
Cheers