需要帮助理解 DTD 架构

发布于 2024-08-10 20:14:55 字数 523 浏览 2 评论 0原文

我对 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 技术交流群。

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

发布评论

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

评论(3

酷遇一生 2024-08-17 20:14:55

这是一个 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).

浮华 2024-08-17 20:14:55

这是一个嵌入的 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.

執念 2024-08-17 20:14:55

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 with person being the root node, name being the first child, having two children which are last_name nodes.

I think the first node under name should be first_name, not last_name.

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