需要帮助理解 DTD 架构
我对 XML 还很陌生,有人能告诉我这段代码到底是做什么的吗?
<?xml version="1.0" encoding="ISO-8859"?>
<!DOCTYPE person [
<!ELEMENT first_name(#PCDATA)>
<!ELEMENT last_name(#PCDATA)>
<!ELEMENT PROFESSION(#PCDATA)>
<!ELEMENT name(first_name, last_name)>
<!ELEMENT person (name, profession)>]>
<person>
<name>
<last_name>Jack</last_name>
<last_name>Jill</last_name>
</name>
</person>
I'm quite new to XML, can someone tell me what exactly this code is supposed to do?
<?xml version="1.0" encoding="ISO-8859"?>
<!DOCTYPE person [
<!ELEMENT first_name(#PCDATA)>
<!ELEMENT last_name(#PCDATA)>
<!ELEMENT PROFESSION(#PCDATA)>
<!ELEMENT name(first_name, last_name)>
<!ELEMENT person (name, profession)>]>
<person>
<name>
<last_name>Jack</last_name>
<last_name>Jill</last_name>
</name>
</person>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个 XML 文件,它本身不执行任何操作。相反,它似乎定义了一个具有两个姓氏的“人”(但该文件无效,因为 DTD 指示了名字和姓氏)。
That is an XML file, and it doesn't do anything by itself. Instead, it appears to define a "person" with two last names (but the file is invalid because the DTD indicates both first name and last name).
这是一个嵌入的 DTD,它规定了哪些元素按何种顺序被允许,例如“name”元素必须包含first_name,后跟last_name。
这是一种非常规的方法,但应该是有效的。通常,DTD 是一个外部文件,而不是嵌入在源文档中。
That's an embedded DTD, which dictates which elements are permitted in which order, e.g. the "name" element must contain first_name followed by last_name.
It's an unconventional approach, but should be valid. Normally the DTD is an external file, rather than being embedded in the source document.
xml 文档首先通过序言 (
) 表明它是一个 xml 文档。定义了一个可选的 DOCTYPE,这基本上只是文档中所有可能元素和属性的列表,最后定义实际文档本身,以
person
作为根节点,name 是第一个子节点,有两个子节点,它们是
last_name
节点。我认为
name
下的第一个节点应该是first_name
,而不是last_name
。The xml document first indicates that it's an xml document by having a prolog (
<?xml
). An optional DOCTYPE is defined, this basically just is a list of all possible elements and attributes in the document, and lastly the actual document itself is defined withperson
being the root node,name
being the first child, having two children which arelast_name
nodes.I think the first node under
name
should befirst_name
, notlast_name
.