在xsd中引用外部xsd

时间:2018-03-18 05:40:51

标签: xml xsd doctype

我正在尝试编写一个xsd,我可以在运行时将另一个xml(我有一个xsd for)文件插入其中。  我不想导入xsd定义以便我可以引用它 - 我希望有一个xml文件的占位符,以便在运行时将其视为xml doc的一部分。

我正在尝试的是以下内容:

<?xml version = "1.0" encoding = "UTF-8" standalone = "no" ?>
<!DOCTYPE doc [
<!ENTITY FilterPassbandDefinitions PUBLIC "passband-lookup.xml" "">
]>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="pathmapping" xmlns:pm="pathmapping">
<xs:element name="pathMapping">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="paths" type="pm:Path" minOccurs="1" maxOccurs="unbounded" />
            <xs:element name="technologies" type="pm:Technology" minOccurs="1" maxOccurs="unbounded" />
            <xs:element name="devices" type="pm:Device" minOccurs="1" maxOccurs="unbounded" />
            <xs:element name="arrayPanel" type="pm:ArrayPanel" minOccurs="1" maxOccurs="unbounded" />
            &FilterPassbandDefinitions;
        </xs:sequence>
    </xs:complexType>
</xs:element>

但是当我尝试验证xsd时,我得到以下投诉:&#34;在#stand; =#34; no&#34;上不再允许伪属性。 &#39; &#34;零件。

如果我删除了&#39; standalone =&#34; no&#34; &#39;然后我得到以下内容:&#34;内容中不允许使用DOCTYPE&#34;

提前致谢。

编辑03/21/18:

我有这两个xml文件,eclipse似乎没有抱怨。它基于以下链接:Can we import XML file into another XML file?

我有以下内容:

otherFile.xml

<?xml version="1.0" encoding="UTF-8" ?>
<doc>
  <foo>
    <bar><baz>this is my content</baz></bar>
  </foo>
</doc>

的test.xml:

<?xml version="1.0" standalone="no" ?>
<!DOCTYPE doc [
<!ENTITY otherFile SYSTEM "otherFile.xml">
]>
<doc>
  <foo>
    <bar>&otherFile;</bar>
  </foo>
</doc>

我现在要做的是为这些文件定义一个xsd。

1 个答案:

答案 0 :(得分:0)

这个让我很困惑,但是您的实体声明的系统ID为“”,它是对当前文档的引用,因此实体引用和FilterPassbandDefinitions递归地提取当前文档的副本,并且这是在不允许的地方包括DOCTYPE声明。如果您将系统ID更改为指向适当的文档,那么这应该可行。 (虽然它是否实际达到你想要做的是另一个问题 - 我认为我不明白你想要做什么。)