格式正确的包含或指向文档类型声明的标记声明 [英] The markup declarations contained or pointed to by the document type declaration must be well-formed

查看:391
本文介绍了格式正确的包含或指向文档类型声明的标记声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个xml文档:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog SYSTEM "plantdtd.dtd">
<catalog>
<title>Flowers of the week</title>
<plant id="A1">
    <name>Aloe vera</name>
    <climate>tropical</climate>
    <height>60-100cm</height>
    <usage>medicinal</usage>
    <image>aloevera.jpg</image>
</plant>
<plant id="A2">
    <name>Orchidaceae</name>
    <height>8-12in</height>
    <usage>medicinal</usage>
    <usage>decoration</usage>
    <image>Orchidaceae.jpg</image>
</plant>
</catalog>

我写了这样的DTD:

<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE catalog SYSTEM "file:/home/p10398/plantdtd.dtd"
[
<!ELEMENT catalog(title,plant+)>
<!ELEMENT title(#PCDATA)>
<!ELEMENT plant(name,climate,height,usage,image)+>
<!ELEMENT name(#PCDATA)>
<!ELEMENT climate(#PCDATA)>
<!ELEMENT height(#PCDATA)>
<!ELEMENT usage(#PCDATA)>
<!ELEMENT image(#PCDATA)>
]>

我收到此错误:

致命错误:
公共ID:空
。系统ID:文件:/home/p14524/plantdtd.dtd
线路数:4
列编号:3
消息:该标记声明必须包含或指向格式为
的文档类型。

Fatal error:                                                                        Public ID: null                                                                  System ID: file:/home/p14524/plantdtd.dtd                                        Line number: 4                                                                   Column number: 3                                                                 Message: The markup declarations contained or pointed to by the document type  declaration must be well-formed.    

有人可以解释为什么我会收到此错误吗?还是正确的DTD?

Can someone explain whay Iam getting this error? or the correct DTD?

编辑和更新:
啊!谢谢丹尼尔。
现在上一个错误消失了。
我的新DTD是

EDITS and UPDATES: Ah! Thanks Daniel. Now the previous error is gone. My new DTD is

<!ELEMENT catalog (title,plant+)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT plant (name,climate,height,usage,image)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT climate (#PCDATA)>
<!ELEMENT height (#PCDATA)>
<!ELEMENT usage (#PCDATA)>
<!ELEMENT image (#PCDATA)>

<!ATTLIST plant id ID #REQUIRED>

我遇到了这个新错误:

行号:18
列编号:9
的消息:元素类型 植物 必须匹配 (名称,气候,高度,用法,图像)

Line number: 18                                                                  Column number: 9                                                                 Message: The content of element type "plant" must match "(name,climate,height,usage,image)".

推荐答案

您需要从DTD中删除 DOCTYPE 。在声明中的元素名称后面也应该有空格。

You need to remove the DOCTYPE from the DTD. You should also have spaces after the element names in the declarations.

新DTD

<!ELEMENT catalog (title,plant+)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT plant (name,climate,height,usage,image)+>
<!ELEMENT name (#PCDATA)>
<!ELEMENT climate (#PCDATA)>
<!ELEMENT height (#PCDATA)>
<!ELEMENT usage (#PCDATA)>
<!ELEMENT image (#PCDATA)>

既然DTD是有效的,则在验证XML时会看到一些错误。

Now that the DTD is valid, you will see a few errors when validating your XML.

首先,您需要声明工厂 id 属性c>元素。我建议使用<!ATTLIST工厂ID ID#REQUIRED> c。

The first is that you need to declare the id attribute of the plant element. I'd suggest <!ATTLIST plant id ID #REQUIRED>.

第二个是<$ c第二个工厂中缺少$ c>气候。我不确定这是XML错误还是DTD错误。尽管 plant 的元素声明没有多大意义,因为这是按顺序排列的这5个元素一次或多次。如果您需要帮助,请描述植物应该包含的内容,我可以帮助您编写正确的声明。

The second is that climate is missing from the second plant. I'm not sure if that's an XML error or a DTD error. The element declaration for plant doesn't make a whole lot of sense though because it's those 5 elements in that order one or more times. If you need help with that piece, describe what plant should contain and I can help you write the right declaration.

这篇关于格式正确的包含或指向文档类型声明的标记声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆