包括另一个XML文件中的XML文件+ XML模式验证

时间:2011-05-18 19:19:51

标签: xml xsd doctype

我有四个三个xml文件和一个xsd文件。 这是文件videodes.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE videodes [
<!ENTITY dvds   SYSTEM "./dvds.xml">
<!ENTITY movies SYSTEM "./movies.xml">
]>
<videodes xsi:noNamespaceSchemaLocation="src/videodes.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  &dvds;
  &movies;
</videodes>

这是文件dvds.xml(在同一目录中):

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

<dvds>
    <dvd id="1">
        <title>The lord of the rings</title>
        <type>Original</type>
        <content>
            <movie movie_id="1"/>
            <movie movie_id="2"/>
            <movie movie_id="3"/>
        </content>
    </dvd>

    <dvd id="2">
        <title>Inception</title>
        <type>Original</type>
        <content>
            <movie movie_id="3"/>
        </content>
    </dvd>
</dvds>

这是文件movies.xml(也在同一目录中):

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

<movies>
    <movie id="1">
        <name>Inception</name>
        <director>Christopher Nolan</director>
        <year>2010</year>
        <country>USA</country>
        <actors>
            <actor>Ellen Page</actor>
        </actors>
        <genres>
            <genre>Thriller</genre>
        </genres>
    </movie>

    <movie id="2">
        <name>Two towers</name>
        <director>Peter Jackson</director>
        <year>2003</year>
        <country>USA</country>
        <actors>
        </actors>
        <genres>
            <genre>Action</genre>
            <genre>Fantasy</genre>
        </genres>
    </movie>

    <movie id="3">
        <name>Return of the king</name>
    </movie>
</movies>

你可以看到我为“main”文件(videodes.xml)编写了一个XML模式。我认为架构并不重要,所以我不会在这里发布。问题是,当我将dvds.xml和movies.xml放在videodes.xml中时,它是有效的(至少这是NetBeans所说的)。但我希望单独存储dvds和电影(不在同一个文件中)。所以我创建了dvds.xml和movies.xml,并将它们包含在videodes.xml中。但是当我现在验证videodes.xml文件时,netbeans说它不是有效的文件。看起来在doctype中声明的文件甚至不包含在videodes.xml中。

我做错了什么?我错了吗?我是否声明了doctype错误?

提前感谢您的任何答案。抱歉我的英语语法错误。

0 个答案:

没有答案