有没有一种方法可以从XML DTD中的另一元素引用元素?
我正在制作一个“学生” XML,该XML存储学生及其信息,例如名称,地址,电话...
在这种情况下,我有一个元素“帮助”内部“额外信息”,我想在其中“参考”帮助该学生及其基本信息的学生。
这是我的代码:
<!ELEMENT students (student+)>
<!ELEMENT student
(name, surname, address, telephone-numbers, procedence,
student-marks*, additional-information, comments)>
<!ATTLIST student ID ID #REQUIRED>
<!ATTLIST student sex (male|female) #IMPLIED>
<!ELEMENT name (#PCDATA)>
<!ELEMENT surname (#PCDATA)>
<!ELEMENT address (street, number, city)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT number (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT telephone-numbers (telefono+)>
<!ELEMENT telephone-number (#PCDATA)>
<!ATTLIST telefono-number headline CDATA #REQUIRED>
<!ELEMENT procedence (province|origin-country)>
<!ELEMENT province (#PCDATA)>
<!ELEMENT origin-country (#PCDATA)>
<!ELEMENT student-marks (#PCDATA|evaluation)*>
<!ELEMENT evaluation (mark)>
<!ATTLIST evaluation evaluation-number (first | second | final) #REQUIRED>
<!ELEMENT mark (#PCDATA)>
<!ELEMENT additional-information (sports-team?, height?, hobbies*, helped-by*)>
<!ELEMENT sports-team (#PCDATA)>
<!ELEMENT height (#PCDATA)>
<!ELEMENT hobbies (#PCDATA)>
<!ELEMENT helped-by ()>
<!ELEMENT comments (comment)>
<!ELEMENT comment (#PCDATA)>
我已经考虑过要做以下操作:
<!ELEMENT helped-by (name, surname)>
但是我不确定这是正确的还是最好的选择。 感谢您的时间,感谢您的时间。
I'm making a 'students' XML that stores students and its information like name, address, telephone...
In this case I have an element 'helped-by' inside 'additional-information' in which I want to "reference" the students that have helped this student and their basic information.
This is my code:
<!ELEMENT students (student+)>
<!ELEMENT student
(name, surname, address, telephone-numbers, procedence,
student-marks*, additional-information, comments)>
<!ATTLIST student ID ID #REQUIRED>
<!ATTLIST student sex (male|female) #IMPLIED>
<!ELEMENT name (#PCDATA)>
<!ELEMENT surname (#PCDATA)>
<!ELEMENT address (street, number, city)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT number (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT telephone-numbers (telefono+)>
<!ELEMENT telephone-number (#PCDATA)>
<!ATTLIST telefono-number headline CDATA #REQUIRED>
<!ELEMENT procedence (province|origin-country)>
<!ELEMENT province (#PCDATA)>
<!ELEMENT origin-country (#PCDATA)>
<!ELEMENT student-marks (#PCDATA|evaluation)*>
<!ELEMENT evaluation (mark)>
<!ATTLIST evaluation evaluation-number (first | second | final) #REQUIRED>
<!ELEMENT mark (#PCDATA)>
<!ELEMENT additional-information (sports-team?, height?, hobbies*, helped-by*)>
<!ELEMENT sports-team (#PCDATA)>
<!ELEMENT height (#PCDATA)>
<!ELEMENT hobbies (#PCDATA)>
<!ELEMENT helped-by ()>
<!ELEMENT comments (comment)>
<!ELEMENT comment (#PCDATA)>
I've thought of doing the following:
<!ELEMENT helped-by (name, surname)>
But I'm unsure if that's correct or the best alternative.
I'd appreciate some advice on the topic, thanks for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于DTD,我建议
IDREF
(有关属性类型的更多信息,请参见此处)。元素看起来像这样:
如果您想允许多个“助手”,则可以使用
idrefs
:该元素看起来像这样(或者可能与上述相同;有多个相应的ID):
此外,属性不必为
refid
。它可以命名其他。For DTD, I'd recommend
IDREF
(see here for more info on attribute types).The element would look like this:
If you wanted to allow more than one "helper", you could use
IDREFS
:The element could look like this (or it could be the same as above; as long as there is more than one corresponding id):
Also, the attribute doesn't have to be
refid
. It can be named something else.