我可以将 !ATTLIST 功能组合到 DTD 的一行中吗?

发布于 2024-11-03 21:00:54 字数 662 浏览 2 评论 0原文

我刚刚学习编写 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短暂陪伴 2024-11-10 21:00:54

好吧,我已经通过执行以下操作使其正常工作,尽管这可能不是“公认的做法”方式:

<!ELEMENT weight (#PCDATA)>
<!ATTLIST weight qty  CDATA "1">
<!ATTLIST weight unit CDATA (kg|lb) "kg">

我必须将值分解为它自己的属性(现在我想这很有意义),并删除 #暗示,因为我在某处读到通过设置默认值,无论如何它都是暗示的。

希望这对其他人有帮助(假设这是正确的方法)

干杯

Ok, I have got it working by doing the following, although it might not be the 'accepted practice' way:

<!ELEMENT weight (#PCDATA)>
<!ATTLIST weight qty  CDATA "1">
<!ATTLIST weight unit CDATA (kg|lb) "kg">

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文