使用DTD时元素“ xi:include”的前缀“ xi”未绑定

问题描述 投票:0回答:1

我想使用xincludes减小已在Java 8应用程序中增长到21K + LOC的xml文件的大小,但遇到以下错误:

Nov 04, 2019 4:27:44 PM com.s3.config.XMLValidatorErrorHandler fatalError
SEVERE: Could not parse file (/path/to/CS_Config.xml). line: 80, The prefix "xi" for element "xi:include" is not bound.

我们目前正在使用DTD进行XML验证,尽管我已经读到架构是一种更好的长期解决方案,但我想在此期间使某些功能正常工作,因为我不确定转换将花费多长时间。到架构文档。

这是我们的主要配置的第80行,在其中添加包括:

<xi:include href="ParametersModbus.xml" />
<xi:include href="Parameters.xml" />
<xi:include href="ParametersVirtual.xml" />

到目前为止,我已经将此添加到了我们的DTD:

<!ELEMENT xi:include (#PCDATA)>
<!ATTLIST xi:include 
    href CDATA #IMPLIED
>

<!ELEMENT Device (xi:include*,Peripheral*,VirtualPeripheral*,Camera*,MachineSync?,MachineChangeDetection?,Buffers?,Expressions?)>

我确实从阅读xinclude上的其他文章中获得了这两个mod:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setXIncludeAware(true);
dbf.setNamespaceAware(true);

不确定我是否需要添加xpointer引用,但有人可以提供建议。

以下是一些相关文章:XML Namespaces and DTD validationTrying to use XInclude with Java and resolving the fragment with xml:idDefault support for xinclude in Java 6?

11/5更新imhotap在下面的回答解决了我的直接问题,当验证关闭时,我们可以处理包含的内容。但是,当我打开验证时,会出现以下行为:

Nov 05, 2019 3:23:42 PM com.s3.config.XMLValidatorErrorHandler error
SEVERE: Could not parse XML file (/home/jchan/eclipse-workspace/filtec-src/src/gui/test_configs/FIL0000/CS_Config.xml). line: 1, Document is invalid: no grammar found.
Nov 05, 2019 3:23:42 PM com.s3.config.XMLValidatorErrorHandler error
SEVERE: Could not parse XML file (/home/jchan/eclipse-workspace/filtec-src/src/gui/test_configs/FIL0000/CS_Config.xml). line: 1, Document root element "Peripheral", must match DOCTYPE root "null". 

是否需要做一些事情而无需在DTD中定义根元素?

11/5更新2看起来我每个包含片段都只需要在包含的文件的根元素之前具有DOCTYPE标记即可。所以在我的情况下是:

<?xml version="1.0"?>
<!DOCTYPE VirtualPeripheral SYSTEM "../../../architecture/peripheral-description/CS_Config.dtd">
java xml dtd xinclude
1个回答
1
投票

即使将“ xi:include”声明为元素,也必须仍然将“ xi”命名空间绑定到XInclude名称空间URI。尝试像这样在您的“ xi:include”元素上将“ xmlns:xi”声明为#FIXED属性:

<!ELEMENT xi:include EMPTY>
<!ATTLIST xi:include 
  href CDATA #IMPLIED
  xmlns:xi CDATA #FIXED "http://www.w3.org/2001/XInclude">

不确定与您的应用程序的普通SGML / XML DTD相比,为什么您认为XML Schema是更好的长期解决方案。如果有的话,XML Schema更加复杂和冗长,并且实现更少。但积极警告其某些功能(例如替代组)。同样,在示例中使用XInclude的功能(包括来自其他文件的片段)可以通过使用普通SGML / XML 实体引用(例如参见Include one XML within another XML and parse it with python)来实现。

© www.soinside.com 2019 - 2024. All rights reserved.